-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLocationLanguageHelper.cs
More file actions
73 lines (67 loc) · 2.48 KB
/
Copy pathLocationLanguageHelper.cs
File metadata and controls
73 lines (67 loc) · 2.48 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Resources.Core;
namespace ControlLibrary.Tools
{
public class LocationLanguageHelper
{
private const string LANG_SETTING = "language";
public const string LANG_CN = "zh-Hans";
public const string LANG_EN = "en-US";
public static void DetermineLanguage()
{
//dp6
//Windows.Globalization.ApplicationPreferences.PreferredLanguage = LANG_CN;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = LANG_CN;
return;
string langSetting = (string)ApplicationDataHelper.ReadSetting(LANG_SETTING);
if (langSetting == LANG_CN || langSetting == LANG_EN)
{
//dp6
//Windows.Globalization.ApplicationPreferences.PreferredLanguage = LANG_CN;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = langSetting;
}
else
{
bool isFindEn = false;
foreach (var defaultLang in ResourceManager.Current.DefaultContext.Languages)
{
if (defaultLang.Contains(LANG_CN))
{
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = LANG_CN;
return;
}
else if (defaultLang.Equals(LANG_EN, StringComparison.Ordinal))
{
isFindEn = true;
}
}
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = isFindEn ? LANG_EN : LANG_CN;
}
}
public static string PreferredLanguage
{
get
{
return Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride;
}
set
{
if (value == LANG_CN || value == LANG_EN)
{
ApplicationDataHelper.WriteSetting(LANG_SETTING, value);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = value;
}
}
}
public static string GetString(string key)
{
var loader = new ResourceLoader();
return loader.GetString(key);
}
}
}