Skip to content

Commit 02931fa

Browse files
committed
Adding localization files and targets. Using Multilingual App Toolkit (MAT) for RESX file and custom tool VsctToXliff (sources added) for VSCT. XLF files are the loc files that vendors localized for us. We translated from RESX and VSCT to XLF, then vendors localize, then we tranlsate it back from localized XLF files to localized RESX and VSCT.
1 parent 3d07b28 commit 02931fa

File tree

140 files changed

+7836
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+7836
-70
lines changed

LibraryManager.Settings.targets

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<ItemGroup>
3+
<DstLocales Include="zh-Hans">
4+
<Lang>chs</Lang>
5+
</DstLocales>
6+
<DstLocales Include="zh-Hant">
7+
<Lang>cht</Lang>
8+
</DstLocales>
9+
<DstLocales Include="cs">
10+
<Lang>csy</Lang>
11+
</DstLocales>
12+
<DstLocales Include="es">
13+
<Lang>esn</Lang>
14+
</DstLocales>
15+
<DstLocales Include="de">
16+
<Lang>deu</Lang>
17+
</DstLocales>
18+
<DstLocales Include="fr">
19+
<Lang>fra</Lang>
20+
</DstLocales>
21+
<DstLocales Include="it">
22+
<Lang>ita</Lang>
23+
</DstLocales>
24+
<DstLocales Include="ja">
25+
<Lang>jpn</Lang>
26+
</DstLocales>
27+
<DstLocales Include="ko">
28+
<Lang>kor</Lang>
29+
</DstLocales>
30+
<DstLocales Include="pl">
31+
<Lang>plk</Lang>
32+
</DstLocales>
33+
<DstLocales Include="pt-Br">
34+
<Lang>ptb</Lang>
35+
</DstLocales>
36+
<DstLocales Include="ru">
37+
<Lang>ru</Lang>
38+
</DstLocales>
39+
<DstLocales Include="tr">
40+
<Lang>trk</Lang>
41+
</DstLocales>
42+
</ItemGroup>
43+
</Project>

LibraryManager.sln

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1515
.editorconfig = .editorconfig
1616
appveyor.yml = appveyor.yml
1717
CHANGELOG.md = CHANGELOG.md
18+
LibraryManager.Settings.targets = LibraryManager.Settings.targets
1819
README.md = README.md
1920
EndProjectSection
2021
EndProject

common/tools/VsctToXliff/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
5+
</startup>
6+
</configuration>

common/tools/VsctToXliff/Program.cs

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/* ****************************************************************************
2+
*
3+
* Copyright (c) Microsoft Corporation.
4+
*
5+
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6+
* copy of the license can be found in the License.html file at the root of this distribution.
7+
* By using this source code in any fashion, you are agreeing to be bound by the terms of
8+
* the Apache License, Version 2.0.
9+
*
10+
* You must not remove this notice, or any other, from this software.
11+
*
12+
* ***************************************************************************/
13+
14+
using System;
15+
using System.IO;
16+
17+
namespace VsctToXliff
18+
{
19+
class Program
20+
{
21+
private static readonly string[] Locales = new[] { "cs", "de", "en", "es", "fr", "it", "ja", "ko", "pl", "pt-BR", "ru", "tr", "zh-Hans", "zh-Hant" };
22+
23+
private static int Main(string[] args)
24+
{
25+
var parsedArgs = new Args(args);
26+
if (parsedArgs.IsError)
27+
{
28+
return -1;
29+
}
30+
31+
switch (parsedArgs.Mode)
32+
{
33+
case Mode.GenerateXliff:
34+
CreateXliffFiles(parsedArgs.SourceFile, parsedArgs.XliffDir);
35+
return 0;
36+
case Mode.GenerateVsct:
37+
CreateVsctFiles(parsedArgs.SourceFile, parsedArgs.XliffDir);
38+
return 0;
39+
case Mode.Error:
40+
default:
41+
Console.WriteLine($"Unexpected processing mode: \'{parsedArgs.Mode}\'.");
42+
return -1;
43+
}
44+
}
45+
46+
private static void CreateXliffFiles(string sourceFile, string xlfDir)
47+
{
48+
if (string.IsNullOrEmpty(sourceFile) || string.IsNullOrEmpty(xlfDir))
49+
{
50+
throw new ArgumentNullException("file and targetDir should be set.");
51+
}
52+
53+
var rootName = Utilities.VsctFileNameWithoutExtension(sourceFile);
54+
55+
var reader = new VsctFile(sourceFile);
56+
var writer = new XliffFile(xlfDir, rootName);
57+
58+
foreach (var locale in Locales)
59+
{
60+
writer.WriteTranslationFile(sourceFile, reader.ReadTranslatableUnits(), locale);
61+
}
62+
}
63+
64+
private static void CreateVsctFiles(string sourceFile, string xlfDir)
65+
{
66+
if (string.IsNullOrEmpty(sourceFile))
67+
{
68+
throw new ArgumentNullException("file should be set.");
69+
}
70+
71+
var targetDir = Path.GetDirectoryName(sourceFile);
72+
var rootName = Utilities.VsctFileNameWithoutExtension(sourceFile);
73+
74+
var vsctFile = new VsctFile(sourceFile);
75+
var xlfFiles = new XliffFile(xlfDir, rootName);
76+
77+
foreach (var locale in Locales)
78+
{
79+
if (StringComparer.OrdinalIgnoreCase.Equals(locale, "en"))
80+
{
81+
// for english just copy the file to a new file name
82+
var destFileName = Path.Combine(targetDir, $"{rootName}.en{VsctFile.VsctExt}");
83+
File.Copy(sourceFile, destFileName, overwrite: true);
84+
}
85+
else
86+
{
87+
var translations = xlfFiles.LoadTranslatedElements(locale);
88+
vsctFile.WriteTranslatedFile(translations, locale);
89+
}
90+
}
91+
}
92+
93+
private class Args
94+
{
95+
public bool IsError { get; }
96+
97+
public string XliffDir { get; }
98+
99+
public string SourceFile { get; }
100+
101+
public Mode Mode { get; }
102+
103+
public Args(string[] args)
104+
{
105+
if (args.Length < 3)
106+
{
107+
this.IsError = true;
108+
DisplayHelp();
109+
}
110+
else
111+
{
112+
this.SourceFile = Utilities.EnsureRootPath(args[0]);
113+
this.XliffDir = Utilities.EnsureRootPath(args[1]);
114+
switch (args[2].ToLowerInvariant())
115+
{
116+
case "--generatexlf":
117+
this.Mode = Mode.GenerateXliff;
118+
break;
119+
case "--generatevsct":
120+
this.Mode = Mode.GenerateVsct;
121+
break;
122+
default:
123+
this.IsError = true;
124+
break;
125+
}
126+
}
127+
}
128+
129+
private void DisplayHelp()
130+
{
131+
Console.WriteLine("usage: VsctToXliff.exe <sourcefile.vsct> <xliff dir> [--generatexlf | --generatevsct].");
132+
Console.WriteLine("--generatexlf\tThis will create xlf files for all VS locales in the xliff dir, overwriting any existing files!");
133+
Console.WriteLine("--generatevsct\tThis will create vsct files for all VS locales in the same dir as the sourecfile.vsct, overwriting any existing files!");
134+
}
135+
}
136+
137+
private enum Mode
138+
{
139+
Error,
140+
GenerateXliff,
141+
GenerateVsct,
142+
}
143+
}
144+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("VsctToXliff")]
8+
[assembly: AssemblyDescription("Tool to generate Xliff files from vsct files, and generate localized vsct files.")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("Microsoft")]
11+
[assembly: AssemblyProduct("VsctToXliff")]
12+
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("bbf7fd3f-26ba-4f6c-8485-f221cca1cf6a")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

common/tools/VsctToXliff/Utilities.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* ****************************************************************************
2+
*
3+
* Copyright (c) Microsoft Corporation.
4+
*
5+
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6+
* copy of the license can be found in the License.html file at the root of this distribution.
7+
* By using this source code in any fashion, you are agreeing to be bound by the terms of
8+
* the Apache License, Version 2.0.
9+
*
10+
* You must not remove this notice, or any other, from this software.
11+
*
12+
* ***************************************************************************/
13+
14+
using System;
15+
using System.IO;
16+
17+
namespace VsctToXliff
18+
{
19+
internal static class Utilities
20+
{
21+
public static string EnsureRootPath(string path)
22+
{
23+
if (Path.IsPathRooted(path))
24+
{
25+
return path;
26+
}
27+
28+
return new FileInfo(Path.Combine(Environment.CurrentDirectory, path)).FullName;
29+
}
30+
31+
/// <returns>The filename without extension or locale.</returns>
32+
public static string VsctFileNameWithoutExtension(string fileName)
33+
{
34+
// assume filename have the following structure: <filename>.<locale>.vsct
35+
var file = Path.GetFileName(fileName);
36+
37+
return file.Substring(0, file.IndexOf('.'));
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)