diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 14c58423..2f26085e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,11 +14,15 @@ jobs: run: | sudo apt-get update -y sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended - + - name: Build uses: ammaraskar/sphinx-action@master with: docs-folder: . + pre-build-command: | + pip install rinohtype + cp _static/__init__.py /usr/local/lib/python3.8/site-packages/rinoh/language + cp _static/bg.py /usr/local/lib/python3.8/site-packages/rinoh/language build-command: "make html rinoh" - name: Deploy HTML diff --git a/_static/__init__.py b/_static/__init__.py new file mode 100644 index 00000000..86fb9a8c --- /dev/null +++ b/_static/__init__.py @@ -0,0 +1,34 @@ +# This file is part of rinohtype, the Python document preparation system. +# +# Copyright (c) Brecht Machiels. +# +# Use of this source code is subject to the terms of the GNU Affero General +# Public License v3. See the LICENSE file or http://www.gnu.org/licenses/. + + +from .cls import Language + +from .en import EN +from .fr import FR +from .it import IT +from .nl import NL +from .de import DE +from .pl import PL +from .cs import CS +from .bg import BG + +__all__ = ['Language', 'EN', 'FR', 'IT', 'NL', 'DE', 'PL', 'CS', 'BG'] + + +# generate docstrings for the Language instances + +for code, language_ref in Language.languages.items(): + language = language_ref() + lines = ['Localized strings for {}'.format(language.name)] + for string_collection in language.strings.values(): + lines.append("\n.. rubric:: {}\n" + .format(type(string_collection).__name__)) + for string in string_collection._strings: + lines.append(":{}: {}".format(string.name, + string_collection[string.name])) + language.__doc__ = '\n'.join(lines) diff --git a/_static/cls.py b/_static/cls.py deleted file mode 100644 index ccf21b4b..00000000 --- a/_static/cls.py +++ /dev/null @@ -1,58 +0,0 @@ -# This file is part of rinohtype, the Python document preparation system. -# -# Copyright (c) Brecht Machiels. -# -# Use of this source code is subject to the terms of the GNU Affero General -# Public License v3. See the LICENSE file or http://www.gnu.org/licenses/. - - -import weakref - -from ..attribute import AttributeType -from ..strings import StringCollection - - -__all__ = ['Language'] - - -class Language(AttributeType): - """Collects localized strings for a particular language - - Args: - code (str): short code identifying the language - name (str): native name of the language - - """ - - languages = {} #: Dictionary mapping codes to :class:`Language`\ s - - def __init__(self, code, name): - self.languages[code] = weakref.ref(self) - self.code = code - self.name = name - self.strings = {} - self.no_break_after = [] - - def __repr__(self): - return "{}('{}', '{}')".format(type(self).__name__, - self.code, self.name) - - def __contains__(self, item): - assert isinstance(item, StringCollection) - strings_class = type(item) - assert strings_class not in self.strings - self.strings[strings_class] = item - - @classmethod - def parse_string(cls, string, source): - return cls.languages[string.lower()]() - - @classmethod - def doc_repr(cls, value): - return ':data:`~.rinoh.language.{}` ({})'.format(value.code.upper(), - value.name) - - @classmethod - def doc_format(cls): - return ('the code of one of the ' - ':ref:`supported languages `') diff --git a/manual.rtt b/manual.rtt index 9a38368a..b6b75755 100644 --- a/manual.rtt +++ b/manual.rtt @@ -8,7 +8,7 @@ parts = contents ;back_matter stylesheet = manual.rts -language = en +language = bg [SectionTitles] contents = 'Съдържание'