Skip to content

Commit 33a154b

Browse files
ja-openaiaurambaj
authored andcommitted
Add file type for VSCode Extension
VSCode Extension uses JSON with simple map id to source string. The source files are package.nls.json and l10n/bundle.l10n.json. Also see docs: https://github.com/microsoft/vscode-extension-samples/tree/main/l10n-sample
1 parent 8bdb008 commit 33a154b

37 files changed

+456
-0
lines changed

cli/src/main/java/com/box/l10n/mojito/cli/filefinder/file/FileTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum FileTypes {
2525
JSON_NOBASENAME(JSONNoBasenameFileType.class),
2626
CHROME_EXT_JSON(ChromeExtensionJSONFileType.class),
2727
FORMATJS_JSON_NOBASENAME(FormatJSJSONNoBasenameFileType.class),
28+
VSCODE_EXTENSION_JSON(VSCodeFileType.class),
2829
I18NEXT_PARSER_JSON(I18NextFileType.class),
2930
TS(TSFileType.class),
3031
YAML(YamlFileType.class),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.box.l10n.mojito.cli.filefinder.file;
2+
3+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.BASE_NAME;
4+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.DOT;
5+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.FILE_EXTENSION;
6+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.LOCALE;
7+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.PARENT_PATH;
8+
9+
import com.box.l10n.mojito.cli.filefinder.locale.AnyLocaleType;
10+
11+
/**
12+
* https://github.com/microsoft/vscode-extension-samples/tree/main/l10n-sample
13+
*
14+
* @author jaurambault
15+
*/
16+
public class VSCodeFileType extends JSONFileType {
17+
18+
public VSCodeFileType() {
19+
this.baseNamePattern = "(package\\.nls|bundle\\.l10n)";
20+
this.sourceFilePatternTemplate =
21+
"{" + PARENT_PATH + "}{" + BASE_NAME + "}" + DOT + "{" + FILE_EXTENSION + "}";
22+
this.targetFilePatternTemplate =
23+
"{"
24+
+ PARENT_PATH
25+
+ "}{"
26+
+ BASE_NAME
27+
+ "}"
28+
+ DOT
29+
+ "{"
30+
+ LOCALE
31+
+ "}"
32+
+ DOT
33+
+ "{"
34+
+ FILE_EXTENSION
35+
+ "}";
36+
this.localeType = new AnyLocaleType();
37+
}
38+
}

cli/src/test/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetCommandTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,48 @@ public void importJsonI18NextParser() throws Exception {
906906
checkExpectedGeneratedResources();
907907
}
908908

909+
@Test
910+
public void importJsonVSCodeExtension() throws Exception {
911+
912+
Repository repository = createTestRepoUsingRepoService();
913+
914+
getL10nJCommander()
915+
.run(
916+
"push",
917+
"-r",
918+
repository.getName(),
919+
"-s",
920+
getInputResourcesTestDir("source").getAbsolutePath(),
921+
"-ft",
922+
"VSCODE_EXTENSION_JSON");
923+
924+
getL10nJCommander()
925+
.run(
926+
"import",
927+
"-r",
928+
repository.getName(),
929+
"-s",
930+
getInputResourcesTestDir("source").getAbsolutePath(),
931+
"-t",
932+
getInputResourcesTestDir("translations").getAbsolutePath(),
933+
"-ft",
934+
"VSCODE_EXTENSION_JSON");
935+
936+
getL10nJCommander()
937+
.run(
938+
"pull",
939+
"-r",
940+
repository.getName(),
941+
"-s",
942+
getInputResourcesTestDir("source").getAbsolutePath(),
943+
"-t",
944+
getTargetTestDir().getAbsolutePath(),
945+
"-ft",
946+
"VSCODE_EXTENSION_JSON");
947+
948+
checkExpectedGeneratedResources();
949+
}
950+
909951
@Test
910952
public void importXcodeXliff() throws Exception {
911953

cli/src/test/java/com/box/l10n/mojito/cli/command/PullCommandTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,57 @@ public void pullJsonI18NextParser() throws Exception {
18191819
checkExpectedGeneratedResources();
18201820
}
18211821

1822+
@Test
1823+
public void pullJsonVSCodeExtension() throws Exception {
1824+
1825+
Repository repository = createTestRepoUsingRepoService();
1826+
1827+
getL10nJCommander()
1828+
.run(
1829+
"push",
1830+
"-r",
1831+
repository.getName(),
1832+
"-s",
1833+
getInputResourcesTestDir("source").getAbsolutePath(),
1834+
"-ft",
1835+
"VSCODE_EXTENSION_JSON");
1836+
1837+
Asset asset = assetClient.getAssetByPathAndRepositoryId("package.nls.json", repository.getId());
1838+
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
1839+
importTranslations(asset.getId(), "source-xliff_", "ja-JP");
1840+
1841+
Asset asset2 =
1842+
assetClient.getAssetByPathAndRepositoryId("l10n/bundle.l10n.json", repository.getId());
1843+
importTranslations(asset2.getId(), "source-xliff_", "fr-FR");
1844+
importTranslations(asset2.getId(), "source-xliff_", "ja-JP");
1845+
1846+
getL10nJCommander()
1847+
.run(
1848+
"pull",
1849+
"-r",
1850+
repository.getName(),
1851+
"-s",
1852+
getInputResourcesTestDir("source").getAbsolutePath(),
1853+
"-t",
1854+
getTargetTestDir("target").getAbsolutePath(),
1855+
"-ft",
1856+
"VSCODE_EXTENSION_JSON");
1857+
1858+
getL10nJCommander()
1859+
.run(
1860+
"pull",
1861+
"-r",
1862+
repository.getName(),
1863+
"-s",
1864+
getInputResourcesTestDir("source_modified").getAbsolutePath(),
1865+
"-t",
1866+
getTargetTestDir("target_modified").getAbsolutePath(),
1867+
"-ft",
1868+
"VSCODE_EXTENSION_JSON");
1869+
1870+
checkExpectedGeneratedResources();
1871+
}
1872+
18221873
@Test
18231874
public void pullFullyTranslated() throws Exception {
18241875

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.box.l10n.mojito.cli.filefinder.file;
2+
3+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.BASE_NAME;
4+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.FILE_EXTENSION;
5+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.LOCALE;
6+
import static com.box.l10n.mojito.cli.filefinder.FilePattern.PARENT_PATH;
7+
8+
import com.box.l10n.mojito.cli.filefinder.FilePattern;
9+
import java.util.regex.Matcher;
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
13+
public class VSCodeFileTypeTest {
14+
15+
@Test
16+
public void testSourcePattern() {
17+
VSCodeFileType vSCodeFileType = new VSCodeFileType();
18+
FilePattern sourceFilePattern = vSCodeFileType.getSourceFilePattern();
19+
Matcher matcher = sourceFilePattern.getPattern().matcher("/l10n/bundle.l10n.json");
20+
Assert.assertTrue(matcher.matches());
21+
Assert.assertEquals("/l10n/", matcher.group(PARENT_PATH));
22+
Assert.assertEquals("bundle.l10n", matcher.group(BASE_NAME));
23+
Assert.assertEquals("json", matcher.group(FILE_EXTENSION));
24+
}
25+
26+
@Test
27+
public void testSourcePatternPakcage() {
28+
VSCodeFileType vSCodeFileType = new VSCodeFileType();
29+
FilePattern sourceFilePattern = vSCodeFileType.getSourceFilePattern();
30+
Matcher matcher = sourceFilePattern.getPattern().matcher("package.nls.json");
31+
Assert.assertTrue(matcher.matches());
32+
Assert.assertEquals("", matcher.group(PARENT_PATH));
33+
Assert.assertEquals("package.nls", matcher.group(BASE_NAME));
34+
Assert.assertEquals("json", matcher.group(FILE_EXTENSION));
35+
}
36+
37+
@Test
38+
public void testTargetPattern() {
39+
VSCodeFileType vSCodeFileType = new VSCodeFileType();
40+
Matcher matcher =
41+
vSCodeFileType.getTargetFilePattern().getPattern().matcher("/l10n/bundle.l10n.fr.json");
42+
Assert.assertTrue(matcher.matches());
43+
Assert.assertEquals("fr", matcher.group(LOCALE));
44+
Assert.assertEquals("/l10n/", matcher.group(PARENT_PATH));
45+
Assert.assertEquals("bundle.l10n", matcher.group(BASE_NAME));
46+
Assert.assertEquals("json", matcher.group(FILE_EXTENSION));
47+
}
48+
49+
@Test
50+
public void testTargetPatternBcp47() {
51+
VSCodeFileType vSCodeFileType = new VSCodeFileType();
52+
Matcher matcher =
53+
vSCodeFileType.getTargetFilePattern().getPattern().matcher("/l10n/bundle.l10n.fr-FR.json");
54+
Assert.assertTrue(matcher.matches());
55+
Assert.assertEquals("fr-FR", matcher.group(LOCALE));
56+
Assert.assertEquals("/l10n/", matcher.group(PARENT_PATH));
57+
Assert.assertEquals("bundle.l10n", matcher.group(BASE_NAME));
58+
Assert.assertEquals("json", matcher.group(FILE_EXTENSION));
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"100_character_description_": "Description de 100 caractères :",
3+
"15_min_duration": "15 min",
4+
"1_day_duration": "1 jour",
5+
"1_hour_duration": "1 heure",
6+
"1_month_duration": "1 mois"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"100_character_description_": "Description de 100 caractères :",
3+
"15_min_duration": "15 min",
4+
"1_day_duration": "1 jour",
5+
"1_hour_duration": "1 heure",
6+
"1_month_duration": "1 mois"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"100_character_description_": "100文字の説明:",
3+
"15_min_duration": "15分",
4+
"1_day_duration": "1日",
5+
"1_hour_duration": "1時間",
6+
"1_month_duration": "1か月"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"100_character_description_": "Description de 100 caractères :",
3+
"15_min_duration": "15 min",
4+
"1_day_duration": "1 jour",
5+
"1_hour_duration": "1 heure",
6+
"1_month_duration": "1 mois"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"100_character_description_": "Description de 100 caractères :",
3+
"15_min_duration": "15 min",
4+
"1_day_duration": "1 jour",
5+
"1_hour_duration": "1 heure",
6+
"1_month_duration": "1 mois"
7+
}

0 commit comments

Comments
 (0)