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

After updating to 1.0.2, XML approach could not get value for neutral language (en culture). #19

Closed
mohamedryan opened this issue Jan 10, 2021 · 5 comments · Fixed by #24
Assignees
Labels
enhancement New feature or request

Comments

@mohamedryan
Copy link

Hi @LazZiya ,

Hope you are doing well,

This issue happened after I updated the localizer version to 1.0.2.
I'm using the XML approach with autoKey and translate options.

Before the translation work perfect for both languages (Arabic, English).

LocSource.ar.xml
image

LocSource.en.xml
image

And the value was getting correctly.
After updating, only the key name is getting with 'en' culture, the Arabic is working fine.

English Culture
image
Arabic Culture
image

I returned to the previous version until the issue is fixed.
I hope this issue is clear to you. And Many Thanks to you.

@LazZiya
Copy link
Owner

LazZiya commented Jan 10, 2021

Hi @mohamedryan ,

I'm fine thanks, hope you are fine too 😊.

The final update 1.0.2 intended to enhance a performance issue when the current culture is same as the TranslateFromCulture. In other words, XLocalizer will skip localizing the source translation culture.

So instead of using coded key strings in the views, you have to use a clear texts of the source translation culture inside the views, e.g.: Assume we have a view with one title and one paragraph, and we have defined TranslateFromCultre = en:

<!-- This will not be localized if current culture in "en" -->
<!-- but will be localized for all other cultures -->
<h1 localize-content>Covid19TipsTitle</h1>
<p localize-content>Covid19TipsDesc</p>
<!-- This will be localized for all cultures other than "en" -->
<!-- since it is a clear "en" text, no need for localization if current culture is "en" -->
<h1 localize-content>COVID-19 Prevention Tips</h1>
<p localize-content>
    Adhere to the rules of spatial distancing...
</p>

You can use any culture in the views, but you have to set the TranslateFromCulture value in XLocalizerOption same as the culture used in views:

services.AddRazorPages()
        .AddXLocalizer<LocSource, MyTranslateService>(ops =>
        {
             // ...
             ops.TranslateFromCulture = "en";
        });

Notice: if you don't set a value for TranslateFromCulture it will be same as the DefaultRequestCulture in RequestLocalizationOptions.

@LazZiya
Copy link
Owner

LazZiya commented Jan 10, 2021

Just re-evaluated your issue, I think it could be a use case where you need to use codes instead of texts inside views. So, I will add an option to bypass or include source translation culture in localization. It will look something like below:

services.AddRazorPages()
        .AddXLocalizer<LocSource, MyTranslateService>(ops =>
        {
             // ...

             // true: don't localize if current culture == source culture
             // false: always localize 
             ops.BypassSourceCulture = false;
        });

By default it will be true that means the source translation culture will not be localized, but if you set the value to false then the source culture will be localized as in the previous version.

I will provide this option in the upcoming update...

@LazZiya LazZiya self-assigned this Jan 10, 2021
@LazZiya LazZiya added the enhancement New feature or request label Jan 10, 2021
@mohamedryan
Copy link
Author

@LazZiya , I believe it will be an important option, as for sure there are some users who used a lot of coded keys, so this update will require him to do many changes in his code.

but for me, I don't have too many coded keys, so I will go with the clear texts for now.

Thanks and Regards. 😄

@LazZiya
Copy link
Owner

LazZiya commented Apr 15, 2021

Fix is now available in XLocalizer v1.0.3 (for XML and RESX resource types). And XLocalizer.DB v1.0.2 (for DB resource type).

Both can be downloaded from nuget:

BR;
Ziya

@LazZiya
Copy link
Owner

LazZiya commented Apr 15, 2021

Explanation to use the fix:

services.AddRazorPages()
    .AddXLocalizer<LocSource, MyMemoryTranslateService>(ops =>
    {
        // ...
        ops.LocalizeDefaultCulture = true;
    });
}

The value of LocalizeDefaultCulture is false by default, just make it true and you will be able to localize default culture as well.

Here is a sample auto added key-value when source-culture and target-cultures are the same:

<data isActive="false">
  <key>Welcome</key>
  <value>Welcome</value>
  <comment>Created by XLocalizer</comment>
</data>

Limitation:

Since online translation services requires two different languages to translate, so online translation will not work when the source and target cultures are same. Anyhow, AutoAddKeys is still available and it will add the key and value to the resource file.

Hope this will help :)

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

Successfully merging a pull request may close this issue.

2 participants