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

Don't insert plural id in translation array #30

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 1 addition & 13 deletions jupyterlab_translate/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def convert_catalog_to_json(po_path: Path, output_dir: Path, project: str) -> Pa
}
}

nplurals_string = po.metadata["Plural-Forms"].split(";")[0]
nplurals = ast.literal_eval(nplurals_string.replace("nplurals=", ""))
# Load existing file in case some old strings need to remain
if json_path.is_file():
data = json.loads(json_path.read_text())
Expand All @@ -54,20 +52,10 @@ def convert_catalog_to_json(po_path: Path, output_dir: Path, project: str) -> Pa
key = entry.msgid

if entry.msgstr:
# result[key] = [None, entry.msgstr]
result[key] = [entry.msgstr]
elif entry.msgstr_plural:
plural = [entry.msgid_plural]

plural = [v for _, v in sorted(entry.msgstr_plural.items())]
result[key] = plural
ordered_plural = sorted(entry.msgstr_plural.items())

for __, msgstr in ordered_plural:
plural.append(msgstr)

# If language has nplurals=1, then add the same translation
if nplurals == 1:
plural[0] = plural[-1]

json_path.write_text(json.dumps(result, sort_keys=True, indent=4))

Expand Down
6 changes: 3 additions & 3 deletions tests/dummy_pkg.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ index fb8ed13..b980cdb 100644
import removeRowSvg from "../style/icons/mdi-table-row-remove.svg";
import { nullTranslator, TranslationBundle } from "@jupyterlab/translation";

@@ -17,16 +17,6 @@ export class SpreadsheetEditorDocumentWidget extends DocumentWidget<SpreadsheetW
const translator = options.translator || nullTranslator;
@@ -18,16 +18,6 @@ export class SpreadsheetEditorDocumentWidget extends DocumentWidget<SpreadsheetW
this._trans = translator.load("spreadsheet-editor");
const a = this._trans._n("singular", "plural");

- const addRowButton = new ToolbarButton({
- icon: new LabIcon({ name: "spreadsheet:add-row", svgstr: addRowSvg }),
Expand All @@ -28,7 +28,7 @@ index fb8ed13..b980cdb 100644
const removeRowButton = new ToolbarButton({
icon: new LabIcon({
name: "spreadsheet:remove-row",
@@ -39,5 +29,27 @@ export class SpreadsheetEditorDocumentWidget extends DocumentWidget<SpreadsheetW
@@ -40,5 +30,27 @@ export class SpreadsheetEditorDocumentWidget extends DocumentWidget<SpreadsheetW
tooltip: this._trans.__("Remove the last row"),
});
this.toolbar.addItem("spreadsheet:remove-row", removeRowButton);
Expand Down
10 changes: 8 additions & 2 deletions tests/dummy_pkg/locale/dummy_pkg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/documentwidget.ts:49
#: src/documentwidget.ts:19
msgid "singular"
msgid_plural "plural"
msgstr[0] ""
msgstr[1] ""

#: src/documentwidget.ts:50
msgid "Remove the last row"
msgstr ""

#: src/documentwidget.ts:62
#: src/documentwidget.ts:63
msgid "Insert a column at the end"
msgstr ""
1 change: 1 addition & 0 deletions tests/dummy_pkg/src/documentwidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class SpreadsheetEditorDocumentWidget extends DocumentWidget<SpreadsheetW
super(options);
const translator = options.translator || nullTranslator;
this._trans = translator.load("spreadsheet-editor");
const a = this._trans._n("singular", "plural");

const addRowButton = new ToolbarButton({
icon: new LabIcon({ name: "spreadsheet:add-row", svgstr: addRowSvg }),
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hatch_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def language_package(tmp_path):
msgstr "마크다운을 표시할 때 사용하는 글꼴.\\n"
"값이 `null`이면 현재 테마의 해당 값이 사용됩니다."

#: packages/notebook-extension/src/index.ts:2505
msgid "Cut Cell"
msgid_plural "Cut Cells"
msgstr[0] "셀 잘라내기"
"""
)
(messages / "spellchecker.po").write_text(
Expand Down Expand Up @@ -198,5 +202,9 @@ def test_hatch_build(language_package):
],
"settings\u0004The font family used to render markdown.\nIf `null`, value from current theme is used.": [
"\ub9c8\ud06c\ub2e4\uc6b4\uc744 \ud45c\uc2dc\ud560 \ub54c \uc0ac\uc6a9\ud558\ub294 \uae00\uaf34.\n\uac12\uc774 `null`\uc774\uba74 \ud604\uc7ac \ud14c\ub9c8\uc758 \ud574\ub2f9 \uac12\uc774 \uc0ac\uc6a9\ub429\ub2c8\ub2e4."
],
"Cut Cell": [
"\uc140\u0020\uc798\ub77c\ub0b4\uae30",
""
]
}"""
6 changes: 4 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def test_create_catalog_with_merge(updated_dummy_pkg):
)
pot = polib.pofile(str(pot_file), wrapwidth=100000, check_for_duplicates=False)

assert len(pot) == 3
assert len(pot) == 4
assert list(map(lambda p: p.msgid, pot)) == [
"Fit columns width",
"Insert a column at the end",
"Remove the last row",
"singular",
]


Expand All @@ -58,10 +59,11 @@ def test_create_catalog_without_merge(updated_dummy_pkg):
)
pot = polib.pofile(str(pot_file), wrapwidth=100000, check_for_duplicates=False)

assert len(pot) == 2
assert len(pot) == 3
assert list(map(lambda p: p.msgid, pot)) == [
"Fit columns width",
"Remove the last row",
"singular",
]


Expand Down