Skip to content

Commit

Permalink
feat: Add basepath for sub-directory of domains
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Mar 23, 2024
1 parent 1d94bf4 commit 67479fc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
29 changes: 24 additions & 5 deletions doc/_locales/ja/LC_MESSAGES/usage/configuration.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: atsphinx-mini18n 0.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-24 01:43+0900\n"
"POT-Creation-Date: 2024-03-24 02:42+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kazuya Takei <[email protected]>\n"
"Language: ja\n"
Expand All @@ -36,7 +36,7 @@ msgstr "拡張の動作をカスタマイズするための設定項目が存在
msgid "Type"
msgstr ""

#: ../../usage/configuration.rst:12
#: ../../usage/configuration.rst:12 ../../usage/configuration.rst:33
msgid "``str``"
msgstr ""

Expand Down Expand Up @@ -83,15 +83,34 @@ msgstr "i18n機能を用いてビルドする対象の言語リスト。言語
msgid "If this is ``None`` , complete to [:confval:`mini18n_default_language`]."
msgstr "この値が ``None`` の場合は、 [:confval:`mini18n_default_language`]とみなします。"

#: ../../usage/configuration.rst:32
#: ../../usage/configuration.rst:34
msgid "``/``"
msgstr ""

#: ../../usage/configuration.rst:35
msgid "``\"/mini18n/\"``"
msgstr ""

#: ../../usage/configuration.rst:37
msgid ""
"This is used to build navigate URL on root document. You edit it if "
"document is deployed on sub-directory of domains."
msgstr "この値はドキュメントルートにアクセスした際のリダイレクト先の判定に用いられます。"
"デプロイ先がドメインのサブディレクトリの場合に編集してください。"

#: ../../usage/configuration.rst:40
msgid "Value must be end with slash."
msgstr "設定値はスラッシュで終わる必要があります。"

#: ../../usage/configuration.rst:43
msgid "Snippets"
msgstr ""

#: ../../usage/configuration.rst:34
#: ../../usage/configuration.rst:45
msgid "You can emmbed snippets in document to navigate easily."
msgstr "言語間の遷移を用意にするために、提供されているスニペットを埋め込むことが出来ます。"

#: ../../usage/configuration.rst:37
#: ../../usage/configuration.rst:48
msgid "Example: set into document used \"Furo\" theme"
msgstr "例: \"Furo\"テーマに使用するコード"

1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# atsphinx.mini18n
mini18n_default_language = "ja"
mini18n_support_languages = ["en", "ja"]
mini18n_basepath = "/mini18n/"


def setup(app):
Expand Down
11 changes: 11 additions & 0 deletions doc/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ There are some options to customize behavior.

If this is ``None`` , complete to [:confval:`mini18n_default_language`].

.. confval:: mini18n_basepath

:Type: ``str``
:Default: ``/``
:Exaple: ``"/mini18n/"``

This is used to build navigate URL on root document.
You edit it if document is deployed on sub-directory of domains.

.. note:: Value must be end with slash.

Snippets
========

Expand Down
2 changes: 2 additions & 0 deletions src/atsphinx/mini18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def autocomplete_config(app: Sphinx, config: Config):
if not config.html_context:
config.html_context = {}
config.html_context["mini18n"] = {
"basepath": config.mini18n_basepath,
"support_languages": config.mini18n_support_languages,
}

Expand All @@ -101,6 +102,7 @@ def setup(app: Sphinx): # noqa: D103
register_i18n_builders(app)
app.add_config_value("mini18n_default_language", None, "env")
app.add_config_value("mini18n_support_languages", [], "env")
app.add_config_value("mini18n_basepath", "/", "env")
app.connect("config-inited", autocomplete_config)
return {
"version": __version__,
Expand Down
9 changes: 6 additions & 3 deletions src/atsphinx/mini18n/templates/mini18n/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
<body>
<script>
const url = new URL(window.location.href);
if (["/", "/index.html"].includes(url.pathname)) {
// TODO: Set default lauguage
url.pathname = "/{{ config.mini18n_default_language }}/";
const targets = [
'{{ config.mini18n_basepath }}',
'{{ config.mini18n_basepath }}/index.html',
];
if (targets.includes(url.pathname)) {
url.pathname = '{{ config.mini18n_basepath }}{{ config.mini18n_default_language }}/';
location.href = url.href;
}
</script>
Expand Down

0 comments on commit 67479fc

Please sign in to comment.