-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathI18n.cs
51 lines (46 loc) · 1.4 KB
/
I18n.cs
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
using NGettext;
using NGettext.Loaders;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Sdx
{
public class I18n
{
private static Dictionary<string, ICatalog> catalogDic = new Dictionary<string, ICatalog>();
private static ICatalog GetCatalog(CultureInfo info)
{
var lang = info.ToString();
if(!catalogDic.ContainsKey(lang))
{
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream("Sdx._locale."+lang+".message.mo");
if (stream == null)
{
catalogDic[lang] = new Catalog(info);
}
else
{
catalogDic[lang] = new Catalog(new MoLoader(stream), info);
}
}
return catalogDic[lang];
}
public static string GetString(string key, params object[] args)
{
return GetCatalog(Sdx.Context.Current.Culture).GetString(key, args);
}
public static string GetPluralString(string text, string pluralText, long n)
{
return GetCatalog(Sdx.Context.Current.Culture).GetPluralString(text, pluralText, n);
}
public static string GetPluralString(string text, string pluralText, long n, params object[] args)
{
return GetCatalog(Sdx.Context.Current.Culture).GetPluralString(text, pluralText, n, args);
}
}
}