From aa13c8f5af137bbedd1781d903e923d45d7c41fb Mon Sep 17 00:00:00 2001 From: James Westman Date: Sun, 5 Jan 2025 14:27:59 -0600 Subject: [PATCH] Warn about single-quoted translated strings gettext only recognizes double quoted strings --- blueprintcompiler/language/values.py | 13 +++++++++++++ docs/translations.rst | 2 ++ tests/sample_errors/single_quoted_translated.blp | 5 +++++ tests/sample_errors/single_quoted_translated.err | 1 + 4 files changed, 21 insertions(+) create mode 100644 tests/sample_errors/single_quoted_translated.blp create mode 100644 tests/sample_errors/single_quoted_translated.err diff --git a/blueprintcompiler/language/values.py b/blueprintcompiler/language/values.py index 5556d99..cb80975 100644 --- a/blueprintcompiler/language/values.py +++ b/blueprintcompiler/language/values.py @@ -58,6 +58,19 @@ class Translated(AstNode): f"Cannot convert translated string to {expected_type.full_name}" ) + @validate("context") + def context_double_quoted(self): + if self.translate_context is None: + return + + if not str(self.group.tokens["context"]).startswith('"'): + raise CompileWarning("gettext may not recognize single-quoted strings") + + @validate("string") + def string_double_quoted(self): + if not str(self.group.tokens["string"]).startswith('"'): + raise CompileWarning("gettext may not recognize single-quoted strings") + @docs() def ref_docs(self): return get_docs_section("Syntax Translated") diff --git a/docs/translations.rst b/docs/translations.rst index 7ebf929..7af2099 100644 --- a/docs/translations.rst +++ b/docs/translations.rst @@ -24,6 +24,8 @@ If you're using Meson's `i18n module