diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-21 22:15:50 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-09-01 17:58:24 +0900 |
| commit | 9b00c31ee26c57998c07fc908666da32442a060d (patch) | |
| tree | 74f1bc837bd76f3ce81a44bf19e90931106a7753 /sphinx/addnodes.py | |
| parent | c6e102999f591948d942797af69284761dd5a3fb (diff) | |
| download | sphinx-git-9b00c31ee26c57998c07fc908666da32442a060d.tar.gz | |
Fix #1734: Could not translate the caption of toctree directive
Diffstat (limited to 'sphinx/addnodes.py')
| -rw-r--r-- | sphinx/addnodes.py | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index 284bc1c75..c5ce4e296 100644 --- a/sphinx/addnodes.py +++ b/sphinx/addnodes.py @@ -14,9 +14,53 @@ import warnings from docutils import nodes -class toctree(nodes.General, nodes.Element): +class translatable: + """Node which supports translation. + + The translation goes forward with following steps: + + 1. Preserve original translatable messages + 2. Apply translated messages from message catalog + 3. Extract preserved messages (for gettext builder) + + The translatable nodes MUST preserve original messages. + And these messages should not be overridden at applying step. + Because they are used at final step; extraction. + """ + + def preserve_original_messages(self): + """Preserve original translatable messages.""" + raise NotImplementedError + + def apply_translated_message(self, original_message, translated_message): + """Apply translated message.""" + raise NotImplementedError + + def extract_original_messages(self): + """Extract translation messages. + + :returns: list of extracted messages or messages generator + """ + raise NotImplementedError + + +class toctree(nodes.General, nodes.Element, translatable): """Node for inserting a "TOC tree".""" + def preserve_original_messages(self): + if 'caption' in self: + self['rawcaption'] = self['caption'] + + def apply_translated_message(self, original_message, translated_message): + if self.get('rawcaption') == original_message: + self['caption'] = translated_message + + def extract_original_messages(self): + if 'rawcaption' in self: + return [self['rawcaption']] + else: + return [] + # domain-specific object descriptions (class, function etc.) |
