Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Factor out common translations to report rows and columns
  • Loading branch information
CyrilleB79 committed Dec 7, 2023
commit 6db8c7d90d3f0f1ebc14929c2e13be4cea1c08b0
58 changes: 28 additions & 30 deletions source/speech/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -1946,22 +1946,11 @@ def getPropertiesSpeech( # noqa: C901

def _rowAndColumnCountText(rowCount: int, columnCount: int) -> Optional[str]:
if rowCount and columnCount:
rowCountTranslation: str = ngettext(
# Translators: Sub-part of the compound string to speak number of columns and rows in a table
"{rowCount} row",
"{rowCount} rows",
rowCount,
).format(rowCount=rowCount)
colCountTranslation: str = ngettext(
# Translators: Sub-part of the compound string to speak number of columns and rows in a table
"{columnCount} column",
"{columnCount} columns",
columnCount,
).format(columnCount=columnCount)
rowCountTranslation: str = _rowCountText(rowCount)
colCountTranslation: str = _columnCountText(columnCount)
# Translators: Main part of the compound string to speak number of columns and rows in a table
# Example output: "with 3 rows and 2 columns"
# In this example {rowCountTranslation} will be replaced by "3 rows" and {colCountTranslation} by
# "2 columns"
# Example: If the reported compound string is "with 3 rows and 2 columns", {rowCountTranslation} will be
# replaced by "3 rows" and {colCountTranslation} by "2 columns"
return _("with {rowCountTranslation} and {colCountTranslation}").format(
rowCountTranslation=rowCountTranslation,
colCountTranslation=colCountTranslation,
Expand All @@ -1975,6 +1964,26 @@ def _rowAndColumnCountText(rowCount: int, columnCount: int) -> Optional[str]:
return None


def _rowCountText(count: int) -> str:
return ngettext(
# Translators: Sub-part of the compound string to speak number of rows and columns in a table.
# Example: If the full compound string is "table with 3 rwos and 2 columns", this substring is "3 rows".
"{rowCount} row",
"{rowCount} rows",
count,
).format(rowCount=count)


def _columnCountText(count: int) -> str:
return ngettext(
# Translators: Sub-part of the compound string to speak number of rows and columns in a table.
# Example: If the full compound string is "table with 3 rwos and 2 columns", this substring is "2 columns".
"{columnCount} column",
"{columnCount} columns",
count,
).format(columnCount=count)


def _shouldSpeakContentFirst(
reason: OutputReason,
role: int,
Expand Down Expand Up @@ -2804,23 +2813,12 @@ def getTableInfoSpeech(
textList=[]
if newTable:
columnCount=tableInfo.get("column-count",0)
# Translators: Sub-part of the compound string to report a table
rowCount=tableInfo.get("row-count",0)
columnCountText = ngettext(
# Translators: Sub-part of the compound string to report a table
"{columnCount} column",
"{columnCount} columns",
columnCount,
).format(columnCount=columnCount)
rowCountText = ngettext(
# Translators: Sub-part of the compound string to report a table
"{rowCount} rows",
"{rowCount} rows",
rowCount,
).format(rowCount=rowCount)
columnCountText = _columnCountText(columnCount)
rowCountText = _rowCountText(rowCount)
# Translators: Main part of the compound string to report a table
# Example output: table with 3 columns and 5 rows
# {columnCountText} is replaced by "3 columns" and {rowCountText} by "5 rows"
# Example: If the reported compound string is "table with 2 columns and 3 rows", {colCountTranslation}
# will be replaced by "2 columns" and {rowCountTranslation} by "3 rows"
text = _("table with {columnCountText} and {rowCountText}").format(
columnCountText=columnCountText,
rowCountText=rowCountText,
Expand Down