forked from fuse-open/fuse-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalization.uno
49 lines (43 loc) · 1.8 KB
/
Localization.uno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Uno.Compiler.ExportTargetInterop;
public class Localization : NativeModule
{
public Localization()
{
AddMember( new NativeFunction("getCurrentLocale", (NativeCallback)GetCurrentLocale) );
}
object GetCurrentLocale(Context c, object[] args)
{
// GetCurrentLocale will return:
// from iOS: [language designator]-[script designator]-[region designator] (e.g. zh-Hans-US, en-US, etc.)
// from Android: [two-leter lowercase language code (ISO 639-1)]_[two-letter uppercase country codes (ISO 3166-1)] (e.g. zh_CN, en_US, etc.)
return GetCurrentLocale();
}
[Foreign(Language.Java)]
static extern(Android) string GetCurrentLocale()
@{
// http://developer.android.com/reference/java/util/Locale.html
// The language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1.
// The country codes are two-letter uppercase ISO country codes (such as "US") as defined by ISO 3166-1.
// The variant codes are unspecified.
// Something like "de_US" for "German as spoken in the US" is possible
return java.util.Locale.getDefault().toString();
@}
[Foreign(Language.ObjC)]
static extern(iOS) string GetCurrentLocale()
@{
// This can return [language designator]-[script designator]-[region designator] (e.g. zh-Hans-US, en-US, etc.)
// https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html
// iOS9+ now supports smarter language fallbacks
// https://developer.apple.com/library/ios/technotes/tn2418/_index.html
return [[NSLocale preferredLanguages] objectAtIndex:0];
@}
static extern(!(iOS||Android)) string GetCurrentLocale()
{
// return the preferred language for unimplemented platforms
return "Default";
}
}