Resource.resx and CultureInfo

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
xwang
Posts: 4
Joined: Mon Sep 05, 2016 5:46 pm

Resource.resx and CultureInfo

Postby xwang » Thu Jan 12, 2017 10:50 pm

Hello Team,

2 questions about Resource file.

Q1
I created a resource file 'DefaultResource.resx' in Projects Configure.
In the file, key-value and culture are setted.
for example: SupportedCultures:ja-JP.

In the simulator, we can get the value according to the key.
But in the browser, exception "No resources available for culture 'ja-JP'." occurred.

Any idea about the error above? An example of how to use resource.resx in CSHTML5 is really helpful.

Q2
In the simulator,we can not get the value ‘System.Globalization.CultureInfo.CurrentUICulture.name’.
Is 'System.Globalization.CultureInfo.CurrentUICulture' supported in CSHTML5?

Thanks.

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Resource.resx and CultureInfo

Postby JS-Support @Userware » Fri Jan 13, 2017 6:17 am

Hi,

Support for "System.Globalization.CultureInfo.CurrentUICulture" is expected in 2017.

RESX files are currently supported but they cannot be localized.

Localizable RESX are on the roadmap for 2017 as well:

http://cshtml5.com/links/roadmap.aspx

If you need the feature quickly, please contact us at sales@cshtml5.com for a quote and precise timescale.

Thanks a lot.
Regards,
JS-Support

xwang
Posts: 4
Joined: Mon Sep 05, 2016 5:46 pm

Re: Resource.resx and CultureInfo

Postby xwang » Tue Jan 17, 2017 10:19 pm

Hi,

Thank you for your reply.
We are going to evaluate the priority of this function in our application.
Will contact the support, if we need more help quickly.

juanpablogc
Posts: 2
Joined: Thu Feb 02, 2017 10:21 pm

Re: Resource.resx and CultureInfo

Postby juanpablogc » Thu Feb 02, 2017 10:27 pm

Hello, this is my first entry in the forum, I have just deployed in Visual Studio the examples and it is really impressive to me. I am decided to create my website with this great platform.

Is there a workaround to get the culture of the thread? is it possible to do with the free edition?

Thank you, my first impression about this is awesome.

berend
Posts: 3
Joined: Fri Aug 17, 2018 6:04 am

Re: Resource.resx and CultureInfo

Postby berend » Thu Nov 01, 2018 10:05 pm

I have applied a fairly simple workaround in my app. The silverlight app is bilingual: the resx strings are en-US with a satellite assembly Dutch nl-NL. However, as the host application supports 5 languages, the workaround should be suitable for more than two languages and handle the fallback to English.

1. Open the nl-NL satellite resx file in notepad++ or similar
2. Give all string ID's a postfix _nl, where nl is the 2-letter language code. If your app supports regional languages, use _nl_NL or language ID like _0413 instead.
For me it was replace [" xml:space="preserve">] by [_nl" xml:space="preserve">]
3. Copy the data part of the satellite strings table to the end of the main resx strings table.
Because I used a postfix, the strings will be sorted by ID, then language in the VS resource editor. This is more convenient than prefix sort if you need to correct translations or add new strings:
Image

The system works if you read strings in code-behind. My app uses a common function, that I changed to handle the new language postfix. In the CSHTML5-version, I pass a 2-letter language ID in a query parameter and store it in the new Language field, the Silverlight version ignores the new field and leaves it as "EN":

Code: Select all

    public static string Language = "EN";
    ...
    public static string GetResource(string sResourceKey)
    {
      string sResource = string.Empty;
      try
      {
        if (Language != "EN")
          sResource = Resources.Strings.ResourceManager.GetString(sResourceKey + "_" + Language.ToLower());
      }
      catch { }
      try
      {
        if (string.IsNullOrEmpty(sResource))
          sResource = Resources.Strings.ResourceManager.GetString(sResourceKey);
      }
      catch (Exception ex) { Common.SendLogToServer(ex); }
      return sResource;
    }

The first try/catch or the check for empty string below cause a fall-back to English if the localized string does not exist, so that the behavior for missing strings is the same as in Silverlight or WPF. As the Silverlight version never sets the Language field, the same code can still exist in both versions of the app (I expect to have to maintain the Silverlight version for at least a year after release of the CSHTML5 equivalent).

To see it in action:
Image
Image
Image

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Resource.resx and CultureInfo

Postby JS-Support @Userware » Fri Nov 02, 2018 7:27 am

Thank you berend for posting this workaround!


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 42 guests