Skip to content

Commit

Permalink
Workaround for a CrowdIn limitation regard offset values
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Feb 25, 2024
1 parent da34b89 commit c67c8fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Languages/en_US/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
few {#rd}
other {#th}
}';
// Interprets ordinal numbers as counting from the end. For example, "2" becomes "2nd to last".
// Interprets ordinal numbers as counting from the end. For example, "2" becomes "2nd to last". Note that some languages need to change the offset value from "offset:0" to "offset:1", but CrowdIn does not allow translators to do that. To work around this limitation, translators can set the value of the "ordinal_last_offset" string to "1". Then SMF will replace "offset:0" with "offset:1" in this string at runtime.
$txt['ordinal_last'] = '{0, selectordinal, offset:0
=1 {last}
one {#st to last}
two {#nd to last}
few {#rd to last}
other {#th to last}
}';
// Interprets ordinal numbers as counting from the end, but spelling out values less than 10. For example, "2" becomes "second to last", but "22" becomes "22nd to last".
// Interprets ordinal numbers as counting from the end, but spelling out values less than 10. For example, "2" becomes "second to last", but "22" becomes "22nd to last". Note that some languages need to change the offset value from "offset:0" to "offset:1", but CrowdIn does not allow translators to do that. To work around this limitation, translators can set the value of the "ordinal_last_offset" string to "1". Then SMF will replace "offset:0" with "offset:1" in this string at runtime.
$txt['ordinal_spellout_last'] = '{0, selectordinal, offset:0
=1 {last}
=2 {second to last}
Expand All @@ -73,6 +73,8 @@
few {#rd to last}
other {#th to last}
}';
// Offset to apply when formatting "ordinal_last" and "ordinal_spellout_last" values. This is a workaround for a CrowdIn limitation that won't let translators change the offset value in those strings. For example, setting this to "1" will cause SMF to change "offset:0" to "offset:1" in those strings at runtime.
$txt['ordinal_last_offset'] = '0';

// Formats for time units.
$txt['number_of_years'] = '{0, plural,
Expand Down
14 changes: 14 additions & 0 deletions Sources/Lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,20 @@ public static function getTxt(string|array $txt_key, array $args = [], string $v
return $target;
}

// Workaround for a CrowdIn limitation that won't allow translators to
// change offset values in strings.
if (
count($txt_key) === 0
&& in_array($txt_key[0], ['ordinal_last', 'ordinal_spellout_last'])
&& isset(self::$txt['ordinal_last_offset'])
) {
$target = str_replace(
'offset:0',
'offset:' . self::$txt['ordinal_last_offset'],
$target,
);
}

return self::formatText($target, $args);
}

Expand Down

0 comments on commit c67c8fc

Please sign in to comment.