Skip to content

Commit c9ff698

Browse files
committed
Localize caption labels
The translations may be wrong for some languages.
1 parent 9002087 commit c9ff698

17 files changed

+476
-30
lines changed

CHANGES.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Changed:
6161

6262
Fixed:
6363

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

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

8485

src/rinoh/image.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .layout import ContainerOverflow, EndOfContainer
2424
from .number import NumberFormat
2525
from .paragraph import StaticParagraph, Paragraph, ParagraphStyle
26+
from .strings import StringCollection, String, StringField
2627
from .structure import ListOf, ListOfSection
2728
from .text import MixedStyledText, SingleStyledText, TextStyle, ErrorText
2829
from .util import posix_path, ReadAliasAttribute, PeekIterator
@@ -397,7 +398,8 @@ def referenceable(self):
397398
def text(self, container):
398399
try:
399400
number = self.number(container)
400-
label = [self.referenceable.category, ' ', number]
401+
category_label = StringField(FloatLabels, self.referenceable.category)
402+
label = [category_label, ' ', number]
401403
except KeyError:
402404
label = []
403405
return MixedStyledText(label + [self.content], parent=self)
@@ -409,12 +411,19 @@ class FigureStyle(FloatStyle, GroupedFlowablesStyle):
409411

410412
class Figure(Float, StaticGroupedFlowables):
411413
style_class = FigureStyle
412-
category = 'Figure'
414+
category = 'figure'
413415

414416

415417
class ListOfFigures(ListOf):
416-
category = 'Figure'
418+
category = 'figure'
417419

418420

419421
class ListOfFiguresSection(ListOfSection):
420422
list_class = ListOfFigures
423+
424+
425+
class FloatLabels(StringCollection):
426+
"""Collection of localized titles for common sections"""
427+
428+
figure = String('Caption label for figures')
429+
table = String('Caption label for tables')

src/rinoh/language/cs.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Obrázek',
18+
table='Tabulka',
19+
) in CS
20+
1521
SectionTitles(
1622
contents='Obsah',
1723
list_of_figures='Seznam obrázků',

src/rinoh/language/de.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Abbildung',
18+
table='Tabelle',
19+
) in DE
20+
1521
SectionTitles(
1622
contents='Inhalt',
1723
list_of_figures='Abbildungsverzeichnis',

src/rinoh/language/en.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Figure',
18+
table='Table',
19+
) in EN
20+
1521
SectionTitles(
1622
contents='Table of Contents',
1723
list_of_figures='List of Figures',

src/rinoh/language/es.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

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

15+
FloatLabels(
16+
figure='Figura',
17+
table='Tabla',
18+
) in ES
19+
1420
SectionTitles(
1521
contents='Contenidos',
1622
list_of_figures='Índice de figuras',

src/rinoh/language/fr.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Figure',
18+
table='Tableau',
19+
) in FR
20+
1521
SectionTitles(
1622
contents='Table des Matières',
1723
list_of_figures='Liste des Figures',

src/rinoh/language/it.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Figura',
18+
table='Tabelle',
19+
) in IT
20+
1521
SectionTitles(
1622
contents='Contenuti',
1723
list_of_figures='Elenco delle Figure',

src/rinoh/language/nl.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Figuur',
18+
table='Tabel',
19+
) in NL
20+
1521
SectionTitles(
1622
contents='Inhoudsopgave',
1723
list_of_figures='Lijst van Figuren',

src/rinoh/language/pl.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88

99
from .cls import Language
10+
from ..image import FloatLabels
1011
from ..structure import SectionTitles, AdmonitionTitles
1112

1213

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

16+
FloatLabels(
17+
figure='Ilustracja',
18+
table='Tabela',
19+
) in PL
20+
1521
SectionTitles(
1622
contents='Spis Treści',
1723
list_of_figures='Spis Ilustracji',

src/rinoh/table.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class TableWithCaptionStyle(FloatStyle, GroupedFlowablesStyle):
422422

423423
class TableWithCaption(Float, StaticGroupedFlowables):
424424
style_class = TableWithCaptionStyle
425-
category = 'Table'
425+
category = 'table'
426426

427427

428428
class TableSection(Styled, list):
@@ -649,7 +649,7 @@ class TableCellBackground(Rectangle):
649649

650650

651651
class ListOfTables(ListOf):
652-
category = 'Table'
652+
category = 'table'
653653

654654

655655
class ListOfTablesSection(ListOfSection):

tests_regression/rst/stringfield.pdf

6.03 KB
Binary file not shown.

tests_regression/rst/stringfield.rst

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ First Chapter
88

99
A paragraph.
1010

11+
.. table:: Truth table for "not"
12+
:widths: auto
13+
14+
===== =====
15+
A not A
16+
===== =====
17+
False True
18+
True False
19+
===== =====
20+
21+
.. figure:: ../images/title.png
22+
23+
Figure caption
24+
1125

1226
Second Chapter
1327
--------------

0 commit comments

Comments
 (0)