
パッケージの構築時に時々発生する問題は、翻訳を有効にすることです。
現在、私は 2 つのパッケージfoo-nl.sty
(オランダ語版) とfoo-en.sty
(英語版) を管理しています。このアプローチの問題点は、もちろん 2 つのパッケージを同期する必要があることですが、同期しているかどうかを確認するメカニズムがありません。
\usepackage[dutch]{babel}
翻訳を提供するための他のオプションはありますか。メイン ドキュメントのコマンドに基づいて、言語も自動的に設定できれば便利です。
答え1
このtranslations
パッケージはまさにこの目的のために開発されました。パッケージには各言語のキーワードの翻訳が提供されています。
\DeclareTranslation{<language>}{<keyword>}{<translation>}
おそらく、
\DeclareTranslationFallback{<keyword>}{<translation>}
babel
翻訳が提供されていない言語を選択した場合に使用されます。
この方法で宣言された翻訳は、
\GetTranslation{<keyword>}
このコマンドは拡張可能なので、hyperref
たとえばブックマークとして使用されるセクション タイトルでも機能します。
以下に短いサンプルパッケージを示します。
\documentclass{article}
\usepackage[english,dutch]{babel}
\usepackage{filecontents}
\begin{filecontents}{mypackage.sty}
\ProvidesPackage{mypackage}
\RequirePackage{translations}
% a command that's translated according to the provided translations:
\newcommand*\mypackagetitle{\section*{\GetTranslation{mypackage-title}}}
% the translations:
% the fallback is used for languages where no specific translation is provided
\DeclareTranslationFallback {mypackage-title}{My title}
\DeclareTranslation{English}{mypackage-title}{My title}
\DeclareTranslation{Dutch} {mypackage-title}{Mijn titel}
\end{filecontents}
\usepackage{mypackage}
\begin{document}
\mypackagetitle
\edef\foo{\GetTranslation{mypackage-title}}
\show\foo
% > \foo=macro:
% ->Mijn titel.
% l.27 \show\foo
\selectlanguage{english}
\mypackagetitle
\edef\foo{\GetTranslation{mypackage-title}}
\show\foo
% > \foo=macro:
% ->My title.
% l.37 \show\foo
\end{document}