mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Simplify Translated
Remove the TranslatedWithContext and TranslatedWithoutContext rules and just use Translated.
This commit is contained in:
parent
779e27d7ac
commit
3c1941a17e
3 changed files with 22 additions and 43 deletions
|
@ -39,8 +39,6 @@ from .values import (
|
||||||
QuotedLiteral,
|
QuotedLiteral,
|
||||||
StringValue,
|
StringValue,
|
||||||
Translated,
|
Translated,
|
||||||
TranslatedWithContext,
|
|
||||||
TranslatedWithoutContext,
|
|
||||||
TypeLiteral,
|
TypeLiteral,
|
||||||
Value,
|
Value,
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,16 +27,10 @@ from .gobject_object import Object
|
||||||
from .contexts import ScopeCtx, ValueTypeCtx
|
from .contexts import ScopeCtx, ValueTypeCtx
|
||||||
|
|
||||||
|
|
||||||
class TranslatedWithoutContext(AstNode):
|
class Translated(AstNode):
|
||||||
grammar = ["_", "(", UseQuoted("string"), Optional(","), ")"]
|
grammar = AnyOf(
|
||||||
|
["_", "(", UseQuoted("string"), Optional(","), ")"],
|
||||||
@property
|
[
|
||||||
def string(self) -> str:
|
|
||||||
return self.tokens["string"]
|
|
||||||
|
|
||||||
|
|
||||||
class TranslatedWithContext(AstNode):
|
|
||||||
grammar = [
|
|
||||||
"C_",
|
"C_",
|
||||||
"(",
|
"(",
|
||||||
UseQuoted("context"),
|
UseQuoted("context"),
|
||||||
|
@ -44,24 +38,17 @@ class TranslatedWithContext(AstNode):
|
||||||
UseQuoted("string"),
|
UseQuoted("string"),
|
||||||
Optional(","),
|
Optional(","),
|
||||||
")",
|
")",
|
||||||
]
|
],
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def string(self) -> str:
|
def string(self) -> str:
|
||||||
return self.tokens["string"]
|
return self.tokens["string"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def translate_context(self) -> str:
|
def translate_context(self) -> T.Optional[str]:
|
||||||
return self.tokens["context"]
|
return self.tokens["context"]
|
||||||
|
|
||||||
|
|
||||||
class Translated(AstNode):
|
|
||||||
grammar = AnyOf(TranslatedWithoutContext, TranslatedWithContext)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def child(self) -> T.Union[TranslatedWithContext, TranslatedWithoutContext]:
|
|
||||||
return self.children[0]
|
|
||||||
|
|
||||||
@validate()
|
@validate()
|
||||||
def validate_for_type(self) -> None:
|
def validate_for_type(self) -> None:
|
||||||
expected_type = self.context[ValueTypeCtx].value_type
|
expected_type = self.context[ValueTypeCtx].value_type
|
||||||
|
@ -382,7 +369,7 @@ class StringValue(AstNode):
|
||||||
@property
|
@property
|
||||||
def string(self) -> str:
|
def string(self) -> str:
|
||||||
if isinstance(self.child, Translated):
|
if isinstance(self.child, Translated):
|
||||||
return self.child.child.string
|
return self.child.string
|
||||||
else:
|
else:
|
||||||
return self.child.value
|
return self.child.value
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class XmlOutput(OutputFormat):
|
||||||
xml.start_tag(
|
xml.start_tag(
|
||||||
"property", **props, **self._translated_string_attrs(child)
|
"property", **props, **self._translated_string_attrs(child)
|
||||||
)
|
)
|
||||||
xml.put_text(child.child.string)
|
xml.put_text(child.string)
|
||||||
xml.end_tag()
|
xml.end_tag()
|
||||||
else:
|
else:
|
||||||
xml.start_tag("property", **props)
|
xml.start_tag("property", **props)
|
||||||
|
@ -149,12 +149,7 @@ class XmlOutput(OutputFormat):
|
||||||
if isinstance(translated, QuotedLiteral):
|
if isinstance(translated, QuotedLiteral):
|
||||||
return {}
|
return {}
|
||||||
else:
|
else:
|
||||||
return {
|
return {"translatable": "true", "context": translated.translate_context}
|
||||||
"translatable": "true",
|
|
||||||
"context": translated.child.translate_context
|
|
||||||
if isinstance(translated.child, TranslatedWithContext)
|
|
||||||
else None,
|
|
||||||
}
|
|
||||||
|
|
||||||
def _emit_signal(self, signal: Signal, xml: XmlEmitter):
|
def _emit_signal(self, signal: Signal, xml: XmlEmitter):
|
||||||
name = signal.name
|
name = signal.name
|
||||||
|
@ -267,7 +262,7 @@ class XmlOutput(OutputFormat):
|
||||||
|
|
||||||
if isinstance(value.child, Translated):
|
if isinstance(value.child, Translated):
|
||||||
xml.start_tag(tag, **attrs, **self._translated_string_attrs(value.child))
|
xml.start_tag(tag, **attrs, **self._translated_string_attrs(value.child))
|
||||||
xml.put_text(value.child.child.string)
|
xml.put_text(value.child.string)
|
||||||
xml.end_tag()
|
xml.end_tag()
|
||||||
elif isinstance(value.child, QuotedLiteral):
|
elif isinstance(value.child, QuotedLiteral):
|
||||||
xml.start_tag(tag, **attrs)
|
xml.start_tag(tag, **attrs)
|
||||||
|
@ -308,7 +303,6 @@ class XmlOutput(OutputFormat):
|
||||||
elif isinstance(extension, Responses):
|
elif isinstance(extension, Responses):
|
||||||
xml.start_tag("responses")
|
xml.start_tag("responses")
|
||||||
for response in extension.responses:
|
for response in extension.responses:
|
||||||
# todo: translated
|
|
||||||
xml.start_tag(
|
xml.start_tag(
|
||||||
"response",
|
"response",
|
||||||
id=response.id,
|
id=response.id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue