From 338cab1660cfde9dbae40d5ce345c8f645f86c52 Mon Sep 17 00:00:00 2001 From: Bartosz Moczulski Date: Tue, 21 Mar 2023 08:49:02 +0100 Subject: [PATCH] i18n: Introduce plural forms for reservations, emails, messages In many languages there is more than one plural form of nouns and rules for choosing the correct one are often far more complex than in English. Luckily both react-i18next and Weblate provide built-in support for translating and selecting plural forms in accordance with grammatical rules of any given language. In order to enable plural forms `{count: n}` option is added to relevant `t()` calls. In translations files "_one" and "_other" suffix is added to English labels such that Weblate can detect which entries represent a set of plural forms and show appropriate language-specific form on the translation page. E.g. in Polish there are 2 plural forms and hence 3 resulting suffixes: "_one", "_few", "_many". Note on transition period: in the absence of expected suffixed variants react-i18next will use non-suffixed one (if present) so existing translations will continue to work just fine even if they happen to be grammatically imperfect. Translators can provide proper plural forms in once this change is merged and Weblate will then replace non-suffixed labels with the suffixed ones. --- web/public/static/langs/en.json | 9 ++++++--- web/src/components/UpgradeDialog.js | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/web/public/static/langs/en.json b/web/public/static/langs/en.json index babdd1dd..8760eb31 100644 --- a/web/public/static/langs/en.json +++ b/web/public/static/langs/en.json @@ -225,10 +225,13 @@ "account_upgrade_dialog_proration_info": "Proration: When upgrading between paid plans, the price difference will be charged immediately. When downgrading to a lower tier, the balance will be used to pay for future billing periods.", "account_upgrade_dialog_reservations_warning_one": "The selected tier allows fewer reserved topics than your current tier. Before changing your tier, please delete at least one reservation. You can remove reservations in the Settings.", "account_upgrade_dialog_reservations_warning_other": "The selected tier allows fewer reserved topics than your current tier. Before changing your tier, please delete at least {{count}} reservations. You can remove reservations in the Settings.", - "account_upgrade_dialog_tier_features_reservations": "{{reservations}} reserved topics", + "account_upgrade_dialog_tier_features_reservations_one": "{{reservations}} reserved topic", + "account_upgrade_dialog_tier_features_reservations_other": "{{reservations}} reserved topics", "account_upgrade_dialog_tier_features_no_reservations": "No reserved topics", - "account_upgrade_dialog_tier_features_messages": "{{messages}} daily messages", - "account_upgrade_dialog_tier_features_emails": "{{emails}} daily emails", + "account_upgrade_dialog_tier_features_messages_one": "{{messages}} daily message", + "account_upgrade_dialog_tier_features_messages_other": "{{messages}} daily messages", + "account_upgrade_dialog_tier_features_emails_one": "{{emails}} daily email", + "account_upgrade_dialog_tier_features_emails_other": "{{emails}} daily emails", "account_upgrade_dialog_tier_features_attachment_file_size": "{{filesize}} per file", "account_upgrade_dialog_tier_features_attachment_total_size": "{{totalsize}} total storage", "account_upgrade_dialog_tier_price_per_month": "month", diff --git a/web/src/components/UpgradeDialog.js b/web/src/components/UpgradeDialog.js index 43be16f5..c62560a3 100644 --- a/web/src/components/UpgradeDialog.js +++ b/web/src/components/UpgradeDialog.js @@ -297,10 +297,10 @@ const TierCard = (props) => { {monthlyPrice > 0 && <>/ {t("account_upgrade_dialog_tier_price_per_month")}} - {tier.limits.reservations > 0 && {t("account_upgrade_dialog_tier_features_reservations", { reservations: tier.limits.reservations })}} + {tier.limits.reservations > 0 && {t("account_upgrade_dialog_tier_features_reservations", { reservations: tier.limits.reservations, count: tier.limits.reservations })}} {tier.limits.reservations === 0 && {t("account_upgrade_dialog_tier_features_no_reservations")}} - {t("account_upgrade_dialog_tier_features_messages", { messages: formatNumber(tier.limits.messages) })} - {t("account_upgrade_dialog_tier_features_emails", { emails: formatNumber(tier.limits.emails) })} + {t("account_upgrade_dialog_tier_features_messages", { messages: formatNumber(tier.limits.messages), count: tier.limits.messages })} + {t("account_upgrade_dialog_tier_features_emails", { emails: formatNumber(tier.limits.emails), count: tier.limits.emails })} {t("account_upgrade_dialog_tier_features_attachment_file_size", { filesize: formatBytes(tier.limits.attachment_file_size, 0) })} {t("account_upgrade_dialog_tier_features_attachment_total_size", { totalsize: formatBytes(tier.limits.attachment_total_size, 0) })}