Skip to content

Commit

Permalink
feat: test theme template translations
Browse files Browse the repository at this point in the history
  • Loading branch information
tillywoodfield committed Jan 22, 2025
1 parent 783c41b commit af021db
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
19 changes: 16 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os.path

import sphinx.application
from sphinx.locale import get_translation

MESSAGE_CATALOG_NAME = "iati-sphinx-theme"
_ = get_translation(MESSAGE_CATALOG_NAME)

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

Expand All @@ -27,19 +35,24 @@
html_theme = "iati_sphinx_theme"
html_theme_options = {
"github_repository": "https://github.com/IATI/sphinx-theme",
"header_title_text": "IATI Sphinx Theme",
"header_title_text": _("IATI Sphinx Theme"),
"languages": {
"en": "English",
"fr": "Français",
"es": "Español",
},
# Uncomment below lines to display tool navigation
# "tool_name": "IATI Example Tool",
# "tool_url": "https://example.com/",
"tool_name": _("IATI Example Tool"),
"tool_url": "https://example.com/",
}

todo_include_todos = True

# -- Options for Texinfo output -------------------------------------------

locale_dirs = ["locale/", "../iati_sphinx_theme/locale"]


def setup(app: sphinx.application.Sphinx) -> None:
locale_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "locale")
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
28 changes: 28 additions & 0 deletions docs/locale/es/LC_MESSAGES/iati-sphinx-theme.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Spanish translations for PROJECT.
# Copyright (C) 2025 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-01-22 13:00+0200\n"
"PO-Revision-Date: 2025-01-21 16:42+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: es\n"
"Language-Team: es <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.14.0\n"

#: conf.py:38
msgid "IATI Sphinx Theme"
msgstr "IATI Sphinx Theme Spanish"

#: conf.py:45
msgid "IATI Example Tool"
msgstr "IATI Example Tool Spanish"

27 changes: 27 additions & 0 deletions docs/locale/iati-sphinx-theme.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Translations template for PROJECT.
# Copyright (C) 2025 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-01-22 13:00+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.14.0\n"

#: conf.py:38
msgid "IATI Sphinx Theme"
msgstr ""

#: conf.py:45
msgid "IATI Example Tool"
msgstr ""

4 changes: 3 additions & 1 deletion iati_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ def setup(app: sphinx.application.Sphinx) -> None:
app.config["html_context"]["language"] = app.config["language"]
app.config["html_context"]["current_year"] = datetime.now().year
app.add_js_file("language-switcher.js")
locale_path = path.join(path.abspath(path.dirname(__file__)), "locale")
theme_path = path.abspath(path.dirname(__file__))
locale_path = path.join(theme_path, "locale")
app.add_message_catalog("sphinx", locale_path)
app.config.templates_path.append(theme_path)
2 changes: 1 addition & 1 deletion iati_sphinx_theme/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h2 class="iati-mobile-nav__label">{{ _("Menu") }}</h2>

<div class="iati-header-title">
<p class="iati-header-title__eyebrow">{{ _("IATI Tools") }}</p>
<p class="iati-header-title__heading">{{ _(theme_header_title_text) }}</p>
<p class="iati-header-title__heading">{{ theme_header_title_text }}</p>
</div>

<div class="iati-header__nav">
Expand Down

0 comments on commit af021db

Please sign in to comment.