Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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)

4 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. $$anonymous$$aybe 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 ins$$anonymous$$d... 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 illu$$anonymous$$ation 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
avatar image
0

Answer by Michael-Ryan · Jul 28, 2020 at 11:20 PM

I had a similar issue when trying to access the "short date" and "short time" formats that the user has defined in the operating system.

 

In my case, Unity recognized that I was using "en-US" for region settings, but it was always returning the default "short date" (M/d/yyy) and "short time" formats, which I has overridden (yyyy-MM-dd). I found a solution similar to calling GetSystemDefaultLCID(), but I used GetLocaleInfoEx() instead. You can use that function to get all sorts of information, including the currency symbols. There are more than 150 values that can be passed to a particular parameter that determines what will be returned. In my posted solution, I only deal with few date and time values, but you can access currency symbols, and much more.

 

Details are posted here: https://stackoverflow.com/questions/63125198/how-to-convert-datetime-to-string-using-region-short-date/63125506#63125506

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.

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

add more country at "systemlanguage" 1 Answer

What is best practice for translation handling? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges