language: Add translation-domain

This allows you to set the translation domain of a blueprint file.
This commit is contained in:
James Westman 2023-12-12 19:31:07 -06:00
parent c5fa33363f
commit e261180dcc
6 changed files with 72 additions and 2 deletions

View file

@ -0,0 +1,31 @@
# translation_domain.py
#
# Copyright 2022 James Westman <james@jwestman.net>
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
from .common import *
class TranslationDomain(AstNode):
grammar = Statement(
"translation-domain",
UseQuoted("domain"),
)
@property
def domain(self):
return self.tokens["domain"]

View file

@ -26,6 +26,7 @@ from .gobject_object import Object
from .gtk_menu import Menu, menu
from .gtkbuilder_template import Template
from .imports import GtkDirective, Import
from .translation_domain import TranslationDomain
class UI(AstNode):
@ -34,6 +35,7 @@ class UI(AstNode):
grammar = [
GtkDirective,
ZeroOrMore(Import),
Optional(TranslationDomain),
Until(
AnyOf(
Template,
@ -75,6 +77,14 @@ class UI(AstNode):
def gtk_decl(self) -> GtkDirective:
return self.children[GtkDirective][0]
@property
def translation_domain(self) -> T.Optional[TranslationDomain]:
domains = self.children[TranslationDomain]
if len(domains):
return domains[0]
else:
return None
@property
def contents(self) -> T.List[T.Union[Object, Template, Menu]]:
return [