localization - Wrong language codes generated by Windows.Globalization.ApplicationLanguages.ManifestLanguages -
i localizing uwp app in several languages using multilingual app toolkit here screen shots of how multilingualresourcesfolder , strings folder looks in project
multilingual resources
strings
all files filled correct values.
in application retrieve list of available languages windows.globalization.applicationlanguages.manifestlanguages
, iterate through them. iteration yields these results
- pt-pt
- ro-ro
- ru
- sk
- sl
this strange because languages declared in exaclty same way languages language code includes locale , doesn't , no reason can undestand.
in way declare them iteration should yield
- pt-pt
- ro-ro
- ru-ru
- sk-sk
- sl-sl
i have tried manually declaring languages in appxmanifest replacing x-generate this
<resources> <resource language="ru-ru"/> <resource language="sk-sk"/> <resource language="pt-pt"/> <resource language="sk-sk"/> <resource language="sl-sl"/> </resources
but results same.
i need application recognize locale language every language. can help?
ok, i've got solution you. there's separate issue you're dealing with, why x-generate in manifest isn't doing right thing (or it?). i'm investigating on side.
so, method want:
public static string getlocalefromlanguage(string identifier) { int result; stringbuilder localename = new stringbuilder(500); result = localefunctions.resolvelocalename(identifier, localename, 500); stringbuilder localedisplay = new stringbuilder(500); result = localefunctions.getlocaleinfoex(localename.tostring(), lctype.locale_senglishdisplayname, localedisplay, 500); return localedisplay.tostring(); }
and of course, you're going need externs:
class localefunctions { // pinvoke declarations [dllimport("kernel32.dll", setlasterror = true, charset = charset.unicode)] public static extern int getlocaleinfoex(string lplocalename, lctype lctype, stringbuilder lplcdata, int cchdata); [dllimport("kernel32.dll", setlasterror = true, charset = charset.unicode)] public static extern int resolvelocalename(string lpnametoresolve, stringbuilder lplocalename, int cchlocalename); }
unfortunately, you're going need declaration lctype. code can found @ link: http://www.pinvoke.net/default.aspx/enums/lctype.html (it's massive chunk of code , don't want copy here.
in code, manually added following language resources manifest (again, i'm not sure why x-generate isn't adding russian locales here, works around it):
<resources> <resource language="en-us" /> <resource language="es-es" /> <resource language="es-mx" /> <resource language="pt-pt" /> <resource language="ro-ro" /> <resource language="ru-ru" /> <resource language="ru-ua" /> </resources>
and method i'm using call in:
private void button_click(object sender, routedeventargs e) { string output = ""; foreach (string thismanifestlanguage in windows.globalization.applicationlanguages.manifestlanguages) { output += thismanifestlanguage + ": "; string resolvedname = localizationtesting.localetest.getlocalefromlanguage(thismanifestlanguage); output += resolvedname + "\n"; } this.outputtext.text = output; }
when called this, output got was:
en-us: english (united states) es-es: spanish (spain, international sort) es-mx: spanish (mexico) pt-pt: portuguese (portugal) ro-ro: romanian (romania) ru: russian (russia) ru-ua: russian (ukraine)
i should point out in getlocalefromlanguage, localename "ru" gets "ru-ru", if that's you're looking for, that's available too.
let me know if doesn't meet needs. i'll see if can reason why in case, had explicitly add ru-ua manifest.
Comments
Post a Comment