forked from JeremyDurnell/locbaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconst.cs
More file actions
99 lines (87 loc) · 3.01 KB
/
const.cs
File metadata and controls
99 lines (87 loc) · 3.01 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//---------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: LocBaml command line tool.
//
//---------------------------------------------------------------------------
using System;
using System.Globalization;
using System.Diagnostics;
using System.Windows.Markup.Localizer;
namespace BamlLocalization
{
internal static class LocBamlConst
{
internal const string BamlAndResourceSeperator = ":";
internal const string ResourceExtension = ".resources";
internal static char GetDelimiter(TranslationFileType fileType)
{
char delimiter;
switch (fileType)
{
case TranslationFileType.CSV:
{
delimiter = ',';
break;
}
case TranslationFileType.TXT:
{
delimiter = '\t';
break;
}
default:
{
Debug.Assert(false, "Un supported FileType");
delimiter = ',';
break;
}
}
return delimiter;
}
internal static bool IsValidCultureName(string name)
{
try
{
// try create a culture to see if the name is a valid culture name
CultureInfo culture = new CultureInfo(name);
return (culture != null);
}
catch (Exception )
{
return false;
}
}
internal static string ResourceKeyToString(BamlLocalizableResourceKey key)
{
return string.Format(
CultureInfo.InvariantCulture,
"{0}:{1}.{2}",
key.Uid,
key.ClassName,
key.PropertyName
);
}
internal static BamlLocalizableResourceKey StringToResourceKey(string value)
{
int nameEnd = value.LastIndexOf(':');
if (nameEnd < 0)
{
throw new ArgumentException(StringLoader.Get("ResourceKeyFormatError"));
}
string name = value.Substring(0, nameEnd);
int classEnd = value.LastIndexOf('.');
if (classEnd < 0 || classEnd < nameEnd || classEnd == value.Length)
{
throw new ArgumentException(StringLoader.Get("ResourceKeyFormatError"));
}
string className = value.Substring(nameEnd + 1, classEnd - nameEnd - 1);
string propertyName = value.Substring(classEnd + 1);
return new BamlLocalizableResourceKey(
name,
className,
propertyName
);
}
}
}