From 02f7ef2ae7665ed7267e9686f8286132d1c5bcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Thu, 9 Nov 2023 10:59:57 +0100 Subject: [PATCH 1/4] Don't insert plural in translation array --- jupyterlab_translate/converters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab_translate/converters.py b/jupyterlab_translate/converters.py index 18b891d..fcd969f 100644 --- a/jupyterlab_translate/converters.py +++ b/jupyterlab_translate/converters.py @@ -57,7 +57,7 @@ def convert_catalog_to_json(po_path: Path, output_dir: Path, project: str) -> Pa # result[key] = [None, entry.msgstr] result[key] = [entry.msgstr] elif entry.msgstr_plural: - plural = [entry.msgid_plural] + plural = [] result[key] = plural ordered_plural = sorted(entry.msgstr_plural.items()) From c3f661a914a4dee7b45050a2af9d2f3b005cac31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Thu, 9 Nov 2023 11:23:57 +0100 Subject: [PATCH 2/4] Add test for plural More fixes --- jupyterlab_translate/converters.py | 14 +------------- tests/dummy_pkg.patch | 6 +++--- tests/dummy_pkg/locale/dummy_pkg.pot | 10 ++++++++-- tests/dummy_pkg/src/documentwidget.ts | 1 + tests/test_hatch_hook.py | 8 ++++++++ 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/jupyterlab_translate/converters.py b/jupyterlab_translate/converters.py index fcd969f..6a5686a 100644 --- a/jupyterlab_translate/converters.py +++ b/jupyterlab_translate/converters.py @@ -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()) @@ -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 = [] - + 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)) diff --git a/tests/dummy_pkg.patch b/tests/dummy_pkg.patch index 3f6109c..881f311 100644 --- a/tests/dummy_pkg.patch +++ b/tests/dummy_pkg.patch @@ -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 Date: Thu, 9 Nov 2023 11:31:18 +0100 Subject: [PATCH 3/4] Fix tests --- tests/test_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0c3c99a..42c1e98 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -40,8 +40,9 @@ 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)) == [ + "singular", "Fit columns width", "Insert a column at the end", "Remove the last row", @@ -58,8 +59,9 @@ 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)) == [ + "singular", "Fit columns width", "Remove the last row", ] From 5688797b2eceaf573fd265fef3ecb5f4b61ea092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Thu, 9 Nov 2023 11:34:00 +0100 Subject: [PATCH 4/4] Fix string order --- tests/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 42c1e98..1d43e0b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -42,10 +42,10 @@ def test_create_catalog_with_merge(updated_dummy_pkg): assert len(pot) == 4 assert list(map(lambda p: p.msgid, pot)) == [ - "singular", "Fit columns width", "Insert a column at the end", "Remove the last row", + "singular", ] @@ -61,9 +61,9 @@ def test_create_catalog_without_merge(updated_dummy_pkg): assert len(pot) == 3 assert list(map(lambda p: p.msgid, pot)) == [ - "singular", "Fit columns width", "Remove the last row", + "singular", ]