-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support label localization #796
Conversation
var localizerType = Type.GetType(localizerTypeName); | ||
var localizer = (IStringLocalizer)HttpContextAccessor.HttpContext.RequestServices.GetService(localizerType); | ||
|
||
ChildContent = @<text>@localizer[$"{ResourceKey}.Text"]</text>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbwalker I don't see any text property for a label component, but I find this line work to set the label text, please let me know your feedback about this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good! what would the RESX file look like to define the localized values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically as:
Name.Text => Nom
Name.HelpText => Entrez Le num do site
Where Name
is the resource name provided in ResourceKey
property
I think this what I understand from your comment before ;)
IMHO many components could be localized that way, and I'm still I see a value if we create a localization sample or localize both |
One additional question I have related to localization is whether it is possible to create RESX files for the default language? For example, Oqtane will display the text in English by default - and currently it is embedded in the razor files - but it would be better if the English resources also came from RESX files so that it is possible to customize the terminology. |
Yep we can, but no need ;) because the default behavior for the localizer is to return the string that passed in as a key |
For labels while the actual keys something like |
Yeah, I am not a big fan of the default behavior of the localizer in .NET Core. It seems very brittle. For example if I add text to a razor file... and then people create alternate RESX localizations in various languages... and then I realize that I mispelled the text in the razor file so I fix the spelling mistake... it will break the localization in every related REX file because the content is the key. In every other aspect of software development you are taught to never use content as a key - a key should be an immutable value. |
Lol, I remembered the early beta's there's a suggestion to add a missing behavior, to use the same key or throw an exception and this I'm currently planned to do in my
Make sense So, shall we merge this if looks good to you, and what about to support other components, we may consider it for future release at least. If this got merged there will be two simple things I need to finish to make a successful localization story in V2 ;) |
Fixes #771