Skip to content
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

Merged
merged 2 commits into from
Oct 13, 2020
Merged

Conversation

hishamco
Copy link
Contributor

Fixes #771

@hishamco
Copy link
Contributor Author

hishamco commented Oct 12, 2020

This show how the "Name" label is localized into French

Localizable Label

var localizerType = Type.GetType(localizerTypeName);
var localizer = (IStringLocalizer)HttpContextAccessor.HttpContext.RequestServices.GetService(localizerType);

ChildContent = @<text>@localizer[$"{ResourceKey}.Text"]</text>;
Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

@hishamco hishamco Oct 12, 2020

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 ;)

@hishamco
Copy link
Contributor Author

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 Oqtane.Server and Oqtane.Client I know the last one it needs time but at least we need a way to provide a way to make the users start quickly using localization without mess ;)

@sbwalker
Copy link
Member

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.

@hishamco
Copy link
Contributor Author

it is possible to create RESX files for the default language?

Yep we can, but no need ;) because the default behavior for the localizer is to return the string that passed in as a key

@hishamco
Copy link
Contributor Author

For labels while the actual keys something like Name.Text and Name.HelpText the locaizer will show them as its for that we may need a English resources to retrieve 'NameandEnter the name` instead

@sbwalker
Copy link
Member

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.

@hishamco
Copy link
Contributor Author

Yeah, I am not a big fan of the default behavior of the localizer in .NET Core

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 JsonStringLocalizer https:/hishamco/My.Extensions.Localization.Json

In every other aspect of software development you are taught to never use content as a key - a key should be an immutable value

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 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support localization for Label component
2 participants