• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by semiessessi · Aug 14, 2013 at 02:17 PM · localizationcurrencylocaleinternationalization

How can I determine the current locale, or at least the currency symbol?

I have tried multiple approaches - but they all return the wrong, or inadequate results.

My test system is set to en-GB out of the box but everything behaves as if it is en-US in Unity (I am testing in the editor).

  • Application.systemLanguage.ToString() returns "English" which is not very helpful at all

  • String.Format( "{0:C}", 0.0f ) gives me a dollar formatted value instead of pounds

  • System.Globalization.RegionInfo.CurrentRegion.CurrencySymbol returns "USD"

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stals · Sep 02, 2016 at 12:34 PM 0
Share

As I can see this now, there is just no good solution, but we can vote for this task would be resolved https://feedback.unity3d.com/suggestions/fix-localization-issues-with-cor (all of my 10 points goes towards it)

3 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by ArkaneX · Aug 17, 2013 at 01:05 AM

After some research, it looks like this is a problem with the Mono version used in Unity - current locale is always returned as "en-US". As a workaround, if your application will work under Windows only, you can use PInvoke (example found here):

 [System.Runtime.InteropServices.DllImport("KERNEL32.DLL")]
 private static extern int GetSystemDefaultLCID();

And then, you can get current culture by calling:

 var currentCulture = new CultureInfo(GetSystemDefaultLCID());

You can also set current culture globally, by using:

 Thread.CurrentThread.CurrentCulture = new CultureInfo(GetSystemDefaultLCID());
 Thread.CurrentThread.CurrentUICulture = new CultureInfo(GetSystemDefaultLCID());

at the beginning of your application. After this, CultureInfo.CurrentCulture (or CurrentUICulture) will return proper info, and {0:C} format should work as expected.

Unfortunately, RegionInfo.CurrentRegion will not return your true RegionInfo. I guess that Unity accesses CurrentRegion property before any of your scripts, and by accessing it, sets it to the earlier culture, which is en-US. But I believe this is not a big issue, as you can always create new RegionInfo(lcid), in case you need it.

One issue which doesn't work - if someone has some specific regional settings in Windows, e.g. changed $ to $$, the currency symbol returned will be $. At least it's the behavior on my machine.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image semiessessi · Sep 06, 2013 at 10:08 AM 0
Share

thanks for taking the time to reply. this confirms my suspicion that this is a bug. unfortunately i am working on a multi-platform title and windows isn't one of our platforms... :/

avatar image ArkaneX · Sep 06, 2013 at 12:09 PM 0
Share

I'm sure each of the platforms you're working with has a native method to get current locale. Maybe even in the same standard LCID form. You can write separate GetSystemDefaultLCID() for each platform, call native method inside, and after receiving data from native call create desired CultureInfo and pass it to current thread cultures.

And then, just conditional compilation symbols around these methods, and you have a solution.

avatar image semiessessi · Sep 06, 2013 at 02:45 PM 0
Share

you are right, i am aware of the various apis available on all of my targets, but this is still a bug, although i can see an argument that it is just incredibly sloppy work instead... i will still make the effort to report it at some point.

since this was for an optional 'stretch' goal i'm not too worried that i can't solve the problem with a reasonable amount of effort... thanks for the extensive feedback though, it is appreciated. :)

avatar image graslany · Jan 12, 2015 at 05:22 PM 2
Share

So we get a brand new real-time global illumination system in unity 5 ... but still no way in 2015 to properly get the user's current language or to use DLLs compiled against something else than the prehistoric 2.0 runtime. This sense of priorities is ... questionable.

avatar image
1

Answer by Darkproduct · Mar 10, 2017 at 07:07 AM

The solution von ArkaneX is fine, but according to this articel: here from stackoverflow We shouldn't use the CultureInfo constructor. A faster way is:

 CultureInfo culture = CultureInfo.GetCultureInfo(GetUserDefaultLCID());

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Piotrku · Jun 30, 2016 at 10:44 PM

Please check out this plugin: http://u3d.as/vXf

You can read user's region and currency symbol using its API

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best practice to internationalize(I18n) a unity project? 2 Answers

Currency localization problem for Yen, Won, and Yuan 3 Answers

IOS App Display Name Internationalizat 1 Answer

What is best practice for translation handling? 0 Answers

add more country at "systemlanguage" 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges