Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nplurals=1 #92

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix context for nplurals=1, add tests
o-kukuruza committed Mar 31, 2020

Verified

This commit was signed with the committer’s verified signature.
ScottGibb Scott Gibb
commit 7f4d6c4ca4002c1e81d0b914f164e06d36e35f1c
1 change: 1 addition & 0 deletions src/lib/flatten.js
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ module.exports = {
if (!flat[kv.key + kv.context]) {
flat[kv.key + kv.context] = {
key: kv.key,
context: kv.context,
};
}
const single = flat[kv.key + kv.context];
8 changes: 8 additions & 0 deletions test/_testfiles/ja/translation.utf8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"a": {
"apple_0": "私はリンゴを{count}個持っています"
},
"friend_0": "{count}人の友達",
"friend_male_0": "{count}人の友達",
"friend_female_0": "{count}人のガールフレンド"
}
25 changes: 25 additions & 0 deletions test/_testfiles/ja/translation.utf8.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0\n"

msgid "a##apple"
msgid_plural "a##apple"
msgstr[0] "私はリンゴを{count}個持っています"

msgid "friend"
msgid_plural "friend"
msgstr[0] "{count}人の友達"

msgctxt "male"
msgid "friend"
msgid_plural "friend"
msgstr[0] "{count}人の友達"

msgctxt "female"
msgid "friend"
msgid_plural "friend"
msgstr[0] "{count}人のガールフレンド"
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -63,6 +63,11 @@ const testFiles = {
utf8_msgid_not_fully_translated_expected:
'./test/_testfiles/ru/translation.utf8_msgid_not_fully_translated.json',
},

ja: {
utf8: './test/_testfiles/ja/translation.utf8.po',
utf8_expected: './test/_testfiles/ja/translation.utf8.json',
},
};

/**
@@ -126,6 +131,12 @@ describe('i18next-gettext-converter', () => {
const expected = requireTestFile(testFiles.ru.utf8_expected);
expect(JSON.parse(result)).to.deep.equal(expected);
}),
gettextToI18next('ja', readFileSync(testFiles.ja.utf8), {
splitNewLine: true,
}).then((result) => {
const expected = requireTestFile(testFiles.ja.utf8_expected);
expect(JSON.parse(result)).to.deep.equal(expected);
}),
]));

it('should convert a latin13 PO files to JSON, for a given domain', () => gettextToI18next('en', readFileSync(testFiles.en.latin13), {
@@ -297,6 +308,13 @@ describe('i18next-gettext-converter', () => {
const expected = readFileSync(testFiles.ru.utf8_2).slice(0, -1); // TODO: figure out last character
expect(result).to.deep.equal(expected);
}),
i18nextToPo('ja', readFileSync(testFiles.ja.utf8_expected), {
splitNewLine: true,
noDate: true,
}).then((result) => {
const expected = readFileSync(testFiles.ja.utf8).slice(0, -1); // TODO: figure out last character
expect(result.toString()).to.deep.equal(expected.toString());
}),
]));

it('should convert a JSON file to utf8 PO with msgid as an original string', () => Promise.all([