I'm working on an application which has an UK English culture ('en-GB'). This application has to display currency values using the correct locale for the country of origin for the data - basically even though the application is English it has to display the Indian Rupees with the correct currency symbol and correct currency separators.
The application also supports other countries, the couple of screen shots shown below are for Italian & Brazilian, you can see the correct currency symbol & separators are being used:
My first attempt to set the correct culture for Indian data was to look up on MSDN for what Silverlight supported. So I believed using either 'hi-IN' or 'gu-IN' should provide what I wanted, but OH NO!
These two cultures aren't supported in WP7 and it will throw an exception if you try and create a CultureInfo class using theses culture names. I then tried to find a list somewhere of supported cultures on the platform. I found several articles on the net, the most promising was about the supported cultures in the App Store (here) and one about using PInvoke on Compact Framework which wouldn't work on the current platform (here).
These two cultures aren't supported in WP7 and it will throw an exception if you try and create a CultureInfo class using theses culture names. I then tried to find a list somewhere of supported cultures on the platform. I found several articles on the net, the most promising was about the supported cultures in the App Store (here) and one about using PInvoke on Compact Framework which wouldn't work on the current platform (here).
I decided to generate my own list of supported cultures. I did this by taking the list provided for Silverlight and attempting to create an instance of each (using a 7.1 (Mango) application), any that didn't throw an exception was a supported culture. The code below is how I generated the list and the list is contained at the bottom of the post.
The outcome is WP7 supports less than the desktop version of Silverlight, not really a surprise:
Silverlight (desktop version) supports 204 cultures,
Silverlight (WP7) supports 164 cultures.
The outcome is WP7 supports less than the desktop version of Silverlight, not really a surprise:
Silverlight (desktop version) supports 204 cultures,
Silverlight (WP7) supports 164 cultures.
private string[] cultureNames = { "", "af", "af-ZA", "sq", "sq-AL", "ar", "ar-DZ", "ar-BHar-EG", "ar-IQ", "ar-JO" , "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-AE", "ar-YE", "hy", "hy-AM", "az", "az-Cyrl-AZ", "az-Latn-AZ", "eu", "eu-ES", "be", "be-BY", "bg", "bg-BG", "ca", "ca-ES", "zh-HK", "zh-MO", "zh-CN", "zh-Hans", "zh-SG", "zh-TW", "zh-Hant", "hr", "hr-BA", "hr-HR", "cs", "cs-CZ", "da", "da-DK", "dv", "dv-MV", "nl", "nl-BE", "nl-NL", "en", "en-AU", "en-BZ", "en-CA", "en-029", "en-IE", "en-JM", "en-NZ", "en-", "en-ZA", "en-TT", "en-GB", "en-US", "en-ZW", "et", "et-EE", "fo", "fo-FO", "fa", "fa-IR", "fi", "fi-FI", "fr", "fr-BE", "fr-CA", "fr-FR", "fr-LU", "fr-MC", "fr-CH", "gl", "gl-ES", "ka", "ka-GE", "de", "de-AT", "de-DE", "de-DE_phoneb", "de-LI", "de-LU", "de-", "el", "el-GR", "gu", "gu-IN", "he", "he-IL", "hi", "hi-IN", "hu", "hu-HU", "is", "is-IS", "id", "id-ID", "it", "it-IT", "it-CH", "ja", "ja-JP", "kn", "kn-IN", "kk", "kk-KZ", "kok", "kok-IN", "ko", "ko-KR", "ky", "ky-KG", "lv", "lv-LV", "lt", "lt-LT", "mk", "mk-MK", "ms", "ms-BN", "ms-MY", "mr", "mr-IN", "mn", "mn-MN", "no", "nb-NO", "nn-NO", "pl", "pl-PL", "pt", "pt-BR", "pt-PT", "pa", "pa-IN", "ro", "ro-RO", "ru", "ru-RU", "sa", "sa-IN", "sr-Cyrl-CS", "sr-Latn-CS", "sk", "sk-SK", "sl", "sl-SI", "es", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-SV", "es-GT", "es-HN" , "es-MX", "es-NI", "es-PA", "es-PY", "es-PE", "es-PR", "es-ES", "es-ES_tradnl" , "es-UY", "es-VE", "sw", "sw-KE", "sv", "sv-FI", "sv-SE", "syr", "syr-SY", "ta", "ta-IN", "tt", "tt-RU", "te", "te-IN", "th", "th-TH", "tr", "tr-TR", "uk" , "uk-UA", "ur", "ur-PK", "uz", "uz-Cyrl-UZ", "uz-Latn-UZ", "vi", "vi-VN" }; private void button1_Click(object sender, System.Windows.RoutedEventArgs e) { Debug.WriteLine("Culture names count - " + cultureNames.Count()); var supportedCultures = cultureNames.Select(CreateCultureInfo).Where(culture => culture != null); Debug.WriteLine("Supported names count - " + supportedCultures.Count()); foreach (var supportedCulture in supportedCultures) { Debug.WriteLine("'{0}','{1}','{2}'", supportedCulture.Name, supportedCulture.DisplayName,supportedCulture.NativeName); } } private CultureInfo CreateCultureInfo(string cultureName) { try { return new CultureInfo(cultureName); } catch (Exception) { return null; } }
From the supported list I had a couple of new ones to try - 'in' & 'gu'. I didn't think these would work but I gave them ago. I was proved correct, both didn't have any usable properties on the instances of the NumberFormatInfo class.
Finally I decided to try the default font for the platform - Segoe WP, or Segoe Windows Phone. A quick search for "Segoe Rupee" brought up this. Not exactly pointing to WP7 but it was a start. A quick test was in order with a 71, (Mango) application:
Bingo!
As you can see the correct Indian Rupee symbol being displayed. All I had to do now was re-factor how we deal with Indian culture requirements for currency. I had to create our own NumberFormatInfo instance with the correct symbol. Below are screen shots from my attempt to get the Rupee symbol displaying on both a 7.0 & 7.1 devices. As expected the 7.1 device handled the unicode (U+20B9) character perfectly fine, but the 7.0 wasn't able to display the required character - see 7.0 (initial). We decided to actually write the text 'Rupee' for 7.0 devices.
You can find out more about the lanaguage support for 7.1 here.
Bingo!
As you can see the correct Indian Rupee symbol being displayed. All I had to do now was re-factor how we deal with Indian culture requirements for currency. I had to create our own NumberFormatInfo instance with the correct symbol. Below are screen shots from my attempt to get the Rupee symbol displaying on both a 7.0 & 7.1 devices. As expected the 7.1 device handled the unicode (U+20B9) character perfectly fine, but the 7.0 wasn't able to display the required character - see 7.0 (initial). We decided to actually write the text 'Rupee' for 7.0 devices.
You can find out more about the lanaguage support for 7.1 here.
To support this scenario is very easy, all we have to do is check the current OS version for the application and act accordingly. We only need to set the CurrencySymbol property so setting a culture for India for this app was easy, but I am aware there are multiple possible languages to support for such a large country. If this had been the case we would have had to be more fine-grain with our definition for the culture.
And that covers off how we are dealing with showing currency information in our application.
And that covers off how we are dealing with showing currency information in our application.
As I said, here is the list of supported cultures on the WP7 platform, this was generated with a Mango 7.1 application in the emulator.
Invariant Language | Invariant Language (Invariant Country) | |
af | Afrikaans | Afrikaans |
af-ZA | Afrikaans | Afrikaans (Suid Afrika) |
sq | Albanian | shqipe |
sq-AL | Albanian | shqipe (Shqipëria) |
ar | العربية | |
hy | Հայերեն | |
az | Azeri (Latin) | Azərbaycanılı |
az-Cyrl-AZ | Azeri (Cyrillic) | Азәрбајҹан (Азәрбајҹан) |
az-Latn-AZ | Azeri (Latin) | Azərbaycanılı (Azərbaycanca) |
eu | Basque | euskara |
eu-ES | Basque | euskara (euskara) |
be | Belarusian | Беларускі |
be-BY | Belarusian | Беларускі (Беларусь) |
bg | Bulgarian | български |
bg-BG | Bulgarian | български (България) |
ca | Catalan | català |
ca-ES | Catalan | català (català) |
zh-HK | Chinese (Hong Kong S.A.R.) | 中文(香港特别行政區) |
zh-MO | Chinese (Macao S.A.R.) | 中文(澳門特别行政區) |
zh-CN | Chinese (PRC) | 中文(中华人民共和国) |
zh-SG | Chinese (Singapore) | 中文(新加坡) |
zh-TW | Chinese (Taiwan) | 中文(繁體) (台灣) |
hr | Croatian | hrvatski |
hr-HR | Croatian | hrvatski (Hrvatska) |
cs | Czech | čeština |
cs-CZ | Czech | čeština (Česká republika) |
da | Danish | dansk |
da-DK | Danish | dansk (Danmark) |
nl | Dutch (Netherlands) | Nederlands |
nl-BE | Dutch (Belgium) | Nederlands (België) |
nl-NL | Dutch (Netherlands) | Nederlands (Nederland) |
en | English (United States) | English |
en-AU | English (Australia) | English (Australia) |
en-BZ | English (Belize) | English (Belize) |
en-CA | English (Canada) | English (Canada) |
en-029 | English (Caribbean) | English (Caribbean) |
en-IE | English (Ireland) | English (Eire) |
en-JM | English (Jamaica) | English (Jamaica) |
en-NZ | English (New Zealand) | English (New Zealand) |
en-ZA | English (South Africa) | English (South Africa) |
en-TT | English (Trinidad and Tobago) | English (Trinidad y Tobago) |
en-GB | English (United Kingdom) | English (United Kingdom) |
en-US | English (United States) | English (United States) |
en-ZW | English (Zimbabwe) | English (Zimbabwe) |
et | Estonian | eesti |
et-EE | Estonian | eesti (Eesti) |
fo | Faroese | føroyskt |
fo-FO | Faroese | føroyskt (Føroyar) |
fa | فارسى | |
fi | Finnish | suomi |
fi-FI | Finnish | suomi (Suomi) |
fr | French (France) | français |
fr-BE | French (Belgium) | français (Belgique) |
fr-CA | French (Canada) | français (Canada) |
fr-FR | French (France) | français (France) |
fr-LU | French (Luxembourg) | français (Luxembourg) |
fr-MC | French (Principality of Monaco) | français (Principauté de Monaco) |
fr-CH | French (Switzerland) | français (Suisse) |
gl | Galician | galego |
gl-ES | Galician | galego (galego) |
ka | ქართული | |
de | German (Germany) | Deutsch |
de-AT | German (Austria) | Deutsch (Österreich) |
de-DE | German (Germany) | Deutsch (Deutschland) |
de-DE | German (Germany) | Deutsch (Deutschland) |
de-LI | German (Liechtenstein) | Deutsch (Liechtenstein) |
de-LU | German (Luxembourg) | Deutsch (Luxemburg) |
el | Greek | ελληνικά |
el-GR | Greek | ελληνικά (Ελλάδα) |
gu | ગુજરાતી | |
he | עברית | |
hi | हिंदी | |
hu | Hungarian | magyar |
hu-HU | Hungarian | magyar (Magyarország) |
is | Icelandic | íslenska |
is-IS | Icelandic | íslenska (Ísland) |
id | Indonesian | Bahasa Indonesia |
id-ID | Indonesian | Bahasa Indonesia (Indonesia) |
it | Italian (Italy) | italiano |
it-IT | Italian (Italy) | italiano (Italia) |
it-CH | Italian (Switzerland) | italiano (Svizzera) |
ja | Japanese | 日本語 |
ja-JP | Japanese | 日本語 (日本) |
kn | ಕನ್ನಡ | |
kk | Қазащb | |
kok | कोंकणी | |
ko | Korean | 한국어 |
ko-KR | Korean | 한국어 (대한민국) |
ky | Kyrgyz | Кыргыз |
ky-KG | Kyrgyz | Кыргыз (Кыргызстан) |
lv | Latvian | latviešu |
lv-LV | Latvian | latviešu (Latvija) |
lt | Lithuanian | lietuvių |
lt-LT | Lithuanian | lietuvių (Lietuva) |
mk | Macedonian (FYROM) | македонски јазик |
mk-MK | Macedonian (FYROM) | македонски јазик (Македонија) |
ms | Malay (Malaysia) | Bahasa Malaysia |
ms-BN | Malay (Brunei Darussalam) | Bahasa Malaysia (Brunei Darussalam) |
ms-MY | Malay (Malaysia) | Bahasa Malaysia (Malaysia) |
mr | मराठी | |
mn | Mongolian (Cyrillic) | Монгол хэл |
mn-MN | Mongolian (Cyrillic) | Монгол хэл (Монгол улс) |
no | Norwegian (Bokmål) | norsk |
nb-NO | Norwegian (Bokmål) | norsk |
bokmål (Norge) | ||
nn-NO | Norwegian (Nynorsk) | norsk |
nynorsk (Noreg) | ||
pl | Polish | polski |
pl-PL | Polish | polski (Polska) |
pt | Portuguese (Brazil) | Português |
pt-BR | Portuguese (Brazil) | Português (Brasil) |
pt-PT | Portuguese (Portugal) | português (Portugal) |
pa | ਪੰਜਾਬੀ | |
ro | Romanian | română |
ro-RO | Romanian | română (România) |
ru | Russian | русский |
ru-RU | Russian | русский (Россия) |
sa | संस्कृत | |
sr-Cyrl-CS | Serbian (Cyrillic | Serbia and Montenegro (Former)) |
српски (Србија) | ||
sr-Latn-CS | Serbian (Latin | Serbia and Montenegro (Former)) |
srpski (Srbija) | ||
sk | Slovak | slovenčina |
sk-SK | Slovak | slovenčina (Slovenská republika) |
sl | Slovenian | slovenski |
sl-SI | Slovenian | slovenski (Slovenija) |
es | Spanish (Spain - Traditional Sort) | español |
es-AR | Spanish (Argentina) | Español (Argentina) |
es-BO | Spanish (Bolivia) | Español (Bolivia) |
es-CL | Spanish (Chile) | Español (Chile) |
es-CO | Spanish (Colombia) | Español (Colombia) |
es-CR | Spanish (Costa Rica) | Español (Costa Rica) |
es-DO | Spanish (Dominican Republic) | Español (República Dominicana) |
es-EC | Spanish (Ecuador) | Español (Ecuador) |
es-SV | Spanish (El Salvador) | Español (El Salvador) |
es-GT | Spanish (Guatemala) | Español (Guatemala) |
es-HN | Spanish (Honduras) | Español (Honduras) |
es-MX | Spanish (Mexico) | Español (México) |
es-NI | Spanish (Nicaragua) | Español (Nicaragua) |
es-PA | Spanish (Panama) | Español (Panamá) |
es-PY | Spanish (Paraguay) | Español (Paraguay) |
es-PE | Spanish (Peru) | Español (Perú) |
es-PR | Spanish (Puerto Rico) | Español (Puerto Rico) |
es-ES | Spanish (Spain - International Sort) | español (España) |
es-ES | Spanish (Spain - Traditional Sort) | español (España) |
es-UY | Spanish (Uruguay) | Español (Uruguay) |
es-VE | Spanish (Bolivarian Republic of Venezuela) | Español (Republica Bolivariana de Venezuela) |
sw | Kiswahili | Kiswahili |
sw-KE | Kiswahili | Kiswahili (Kenya) |
sv | Swedish (Sweden) | svenska |
sv-FI | Swedish (Finland) | svenska (Finland) |
sv-SE | Swedish (Sweden) | svenska (Sverige) |
syr | ܣܘܪܝܝܐ | |
ta | தமிழ் | |
tt | Tatar | Татар |
tt-RU | Tatar | Татар (Россия) |
te | తెలుగు | |
th | ไทย | |
tr | Turkish | Türkçe |
tr-TR | Turkish | Türkçe (Türkiye) |
uk | Ukrainian | україньска |
uk-UA | Ukrainian | україньска (Україна) |
ur | اُردو | |
uz | Uzbek (Latin) | Uzbek |
uz-Cyrl-UZ | Uzbek (Cyrillic) | Ўзбек (Ўзбекистон) |
uz-Latn-UZ | Uzbek (Latin) | Uzbek (Uzbekiston Respublikasi) |
vi | Tiếng Việt |
It seems that there is such "en-IN" culture that is supported by WP7.1 and it formats the currency with rupee symbol.
ReplyDeleteI.e. the code:
CultureInfo culture = new CultureInfo("en-IN");
string currency = string.Format(culture, "{0}, {1:C}", culture.Name, 123.45);
creates following string:
en-IN, ₹ 123.45
It appears this was added for the RTM version of 7.1.
ReplyDeleteThanks for the info.