Skip to content

Commit

Permalink
Localize caption labels
Browse files Browse the repository at this point in the history
The translations may be wrong for some languages.
  • Loading branch information
brechtm committed Jun 14, 2024
1 parent 9002087 commit c9ff698
Show file tree
Hide file tree
Showing 17 changed files with 476 additions and 30 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Changed:

Fixed:

* Caption labels ("Figure" ad "Table") were not localized
* Rendering of tables with no body (#420, PR #422 by th0mr)
* Hyphenation of the first word on a line (#188, #416)
* AttributeError: 'ZeroWidthSpace' object has no attribute 'hyphenate' (#415,
Expand All @@ -78,7 +79,7 @@ Fixed:

- Some fonts on Google Fonts have the 'otf' extension (instead of 'ttf');
also collect these.
- Look recursively for font files in the a Google Fonts directory (e.g. Asap
- Look recursively for font files in a Google Fonts directory (e.g. Asap
fonts are now stored in a deeper directory).


Expand Down
15 changes: 12 additions & 3 deletions src/rinoh/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .layout import ContainerOverflow, EndOfContainer
from .number import NumberFormat
from .paragraph import StaticParagraph, Paragraph, ParagraphStyle
from .strings import StringCollection, String, StringField
from .structure import ListOf, ListOfSection
from .text import MixedStyledText, SingleStyledText, TextStyle, ErrorText
from .util import posix_path, ReadAliasAttribute, PeekIterator
Expand Down Expand Up @@ -397,7 +398,8 @@ def referenceable(self):
def text(self, container):
try:
number = self.number(container)
label = [self.referenceable.category, ' ', number]
category_label = StringField(FloatLabels, self.referenceable.category)
label = [category_label, ' ', number]
except KeyError:
label = []
return MixedStyledText(label + [self.content], parent=self)
Expand All @@ -409,12 +411,19 @@ class FigureStyle(FloatStyle, GroupedFlowablesStyle):

class Figure(Float, StaticGroupedFlowables):
style_class = FigureStyle
category = 'Figure'
category = 'figure'


class ListOfFigures(ListOf):
category = 'Figure'
category = 'figure'


class ListOfFiguresSection(ListOfSection):
list_class = ListOfFigures


class FloatLabels(StringCollection):
"""Collection of localized titles for common sections"""

figure = String('Caption label for figures')
table = String('Caption label for tables')
6 changes: 6 additions & 0 deletions src/rinoh/language/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


CS = Language('cs', 'Česky')

FloatLabels(
figure='Obrázek',
table='Tabulka',
) in CS

SectionTitles(
contents='Obsah',
list_of_figures='Seznam obrázků',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


DE = Language('de', 'Deutsch')

FloatLabels(
figure='Abbildung',
table='Tabelle',
) in DE

SectionTitles(
contents='Inhalt',
list_of_figures='Abbildungsverzeichnis',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


EN = Language('en', 'English')

FloatLabels(
figure='Figure',
table='Table',
) in EN

SectionTitles(
contents='Table of Contents',
list_of_figures='List of Figures',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles

ES = Language('es', 'Spanish')

FloatLabels(
figure='Figura',
table='Tabla',
) in ES

SectionTitles(
contents='Contenidos',
list_of_figures='Índice de figuras',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


FR = Language('fr', 'Français')

FloatLabels(
figure='Figure',
table='Tableau',
) in FR

SectionTitles(
contents='Table des Matières',
list_of_figures='Liste des Figures',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


IT = Language('it', 'Italiano')

FloatLabels(
figure='Figura',
table='Tabelle',
) in IT

SectionTitles(
contents='Contenuti',
list_of_figures='Elenco delle Figure',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


NL = Language('nl', 'Nederlands')

FloatLabels(
figure='Figuur',
table='Tabel',
) in NL

SectionTitles(
contents='Inhoudsopgave',
list_of_figures='Lijst van Figuren',
Expand Down
6 changes: 6 additions & 0 deletions src/rinoh/language/pl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@


from .cls import Language
from ..image import FloatLabels
from ..structure import SectionTitles, AdmonitionTitles


PL = Language('pl', 'Polski')

FloatLabels(
figure='Ilustracja',
table='Tabela',
) in PL

SectionTitles(
contents='Spis Treści',
list_of_figures='Spis Ilustracji',
Expand Down
4 changes: 2 additions & 2 deletions src/rinoh/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class TableWithCaptionStyle(FloatStyle, GroupedFlowablesStyle):

class TableWithCaption(Float, StaticGroupedFlowables):
style_class = TableWithCaptionStyle
category = 'Table'
category = 'table'


class TableSection(Styled, list):
Expand Down Expand Up @@ -649,7 +649,7 @@ class TableCellBackground(Rectangle):


class ListOfTables(ListOf):
category = 'Table'
category = 'table'


class ListOfTablesSection(ListOfSection):
Expand Down
Binary file modified tests_regression/rst/stringfield.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions tests_regression/rst/stringfield.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ First Chapter

A paragraph.

.. table:: Truth table for "not"
:widths: auto

===== =====
A not A
===== =====
False True
True False
===== =====

.. figure:: ../images/title.png

Figure caption


Second Chapter
--------------
Expand Down
Loading

0 comments on commit c9ff698

Please sign in to comment.