From 55e5095fbafa8096b3d8cb9624017467465cea9c Mon Sep 17 00:00:00 2001 From: James Westman Date: Fri, 3 Jan 2025 18:56:24 -0600 Subject: [PATCH] values: Don't allow translated strings in arrays Gtk.Builder has no way to translate individual strings in a string array, so don't allow it in the syntax. --- blueprintcompiler/language/values.py | 8 ++++++++ tests/sample_errors/translated_string_array.blp | 7 +++++++ tests/sample_errors/translated_string_array.err | 1 + 3 files changed, 16 insertions(+) create mode 100644 tests/sample_errors/translated_string_array.blp create mode 100644 tests/sample_errors/translated_string_array.err diff --git a/blueprintcompiler/language/values.py b/blueprintcompiler/language/values.py index 63cf4fc..5f47e54 100644 --- a/blueprintcompiler/language/values.py +++ b/blueprintcompiler/language/values.py @@ -452,6 +452,14 @@ class ArrayValue(AstNode): range=quoted_literal.range, ) ) + elif isinstance(value.child, Translated): + errors.append( + CompileError( + "Arrays can't contain translated strings", + range=value.child.range, + ) + ) + if len(errors) > 0: raise MultipleErrors(errors) diff --git a/tests/sample_errors/translated_string_array.blp b/tests/sample_errors/translated_string_array.blp new file mode 100644 index 0000000..451d900 --- /dev/null +++ b/tests/sample_errors/translated_string_array.blp @@ -0,0 +1,7 @@ +using Gtk 4.0; + +StringList { + strings: [ + _("Test") + ]; +} diff --git a/tests/sample_errors/translated_string_array.err b/tests/sample_errors/translated_string_array.err new file mode 100644 index 0000000..0beb7e5 --- /dev/null +++ b/tests/sample_errors/translated_string_array.err @@ -0,0 +1 @@ +5,5,9,Arrays can't contain translated strings \ No newline at end of file