From 83c12a817c55d4f3ba1a3daa1510c995d4aa8a53 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Tue, 2 Mar 2021 13:18:10 +0100 Subject: [PATCH] Add possibility of migrating plural forms --- lib/l10n/intl_ca.arb | 3 +- lib/l10n/intl_da.arb | 3 +- lib/l10n/intl_de.arb | 3 +- lib/l10n/intl_el.arb | 3 +- lib/l10n/intl_en.arb | 8 +- lib/l10n/intl_eo.arb | 3 +- lib/l10n/intl_es.arb | 3 +- lib/l10n/intl_eu.arb | 3 +- lib/l10n/intl_fa.arb | 3 +- lib/l10n/intl_fi.arb | 3 +- lib/l10n/intl_fr.arb | 3 +- lib/l10n/intl_hu.arb | 3 +- lib/l10n/intl_it.arb | 3 +- lib/l10n/intl_ja.arb | 3 +- lib/l10n/intl_ka.arb | 3 +- lib/l10n/intl_ko.arb | 3 +- lib/l10n/intl_nl.arb | 3 +- lib/l10n/intl_pt_BR.arb | 3 +- lib/l10n/intl_sq.arb | 3 +- lib/l10n/intl_sv.arb | 3 +- lib/l10n/intl_tr.arb | 3 +- lib/l10n/intl_zh.arb | 3 +- lib/l10n/l10n_from_string.dart | 1 + lib/l10n/untranslated.json | 184 +++++++++++++++++++++++++++--- scripts/gen_l10n_from_string.dart | 8 +- scripts/migrate_lemmy_l10n.dart | 41 ++++++- 26 files changed, 265 insertions(+), 40 deletions(-) diff --git a/lib/l10n/intl_ca.arb b/lib/l10n/intl_ca.arb index 149ec45..52f5400 100644 --- a/lib/l10n/intl_ca.arb +++ b/lib/l10n/intl_ca.arb @@ -94,5 +94,6 @@ "no_private_message_edit_allowed": "No teniu permisos per a editar el missatge privat.", "post_title_too_long": "El títol de l’apunt és massa llarg.", "email_already_exists": "L’adreça ja és en ús.", - "user_already_exists": "L’usuari ja existeix." + "user_already_exists": "L’usuari ja existeix.", + "number_users_online": "{count,plural, =1{{count} usuari en línia} other{{count} usuaris en línia}}" } diff --git a/lib/l10n/intl_da.arb b/lib/l10n/intl_da.arb index e37e57b..26dd1e3 100644 --- a/lib/l10n/intl_da.arb +++ b/lib/l10n/intl_da.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Ulovligt at ændre i privat besked.", "post_title_too_long": "Indlægstitel for lang.", "email_already_exists": "Emailen findes allerede.", - "user_already_exists": "Brugeren findes allerede." + "user_already_exists": "Brugeren findes allerede.", + "number_users_online": "{count,plural, =1{{count} Bruger Online} other{{count} Brugere Online}}" } diff --git a/lib/l10n/intl_de.arb b/lib/l10n/intl_de.arb index 74e8c87..54598cd 100644 --- a/lib/l10n/intl_de.arb +++ b/lib/l10n/intl_de.arb @@ -101,5 +101,6 @@ "no_private_message_edit_allowed": "Editieren der Privatnachricht nicht erlaubt.", "post_title_too_long": "Posttitel zu lang.", "email_already_exists": "Email existiert bereits.", - "user_already_exists": "Nutzer existiert bereits." + "user_already_exists": "Nutzer existiert bereits.", + "number_users_online": "{count,plural, =1{{count} Benutzer online} other{{count} Benutzer*innen online}}" } diff --git a/lib/l10n/intl_el.arb b/lib/l10n/intl_el.arb index f777e75..3bb419a 100644 --- a/lib/l10n/intl_el.arb +++ b/lib/l10n/intl_el.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Δεν επιτρέπεται η επεξεργασία του προσωπικού μηνύματος.", "post_title_too_long": "Η επικεφαλίδα της δημοσίευσης είναι υπερβολικά μεγάλη.", "email_already_exists": "Η διεύθυνση ηλεκτρονικού ταχυδρομείου υπάρχει ήδη.", - "user_already_exists": "Ο χρήστης υπάρχει ήδη." + "user_already_exists": "Ο χρήστης υπάρχει ήδη.", + "number_users_online": "{count,plural, =1{{count} ενεργός χρήστης} other{{count} ενεργοί χρήστες}}" } diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index eee314b..96b5e35 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -225,5 +225,11 @@ "email_already_exists": "Email already exists.", "@email_already_exists": {}, "user_already_exists": "User already exists.", - "@user_already_exists": {} + "@user_already_exists": {}, + "number_users_online": "{count,plural, =1{{count} user online} other{{count} users online}}", + "@number_users_online": { + "placeholders": { + "count": {} + } + } } diff --git a/lib/l10n/intl_eo.arb b/lib/l10n/intl_eo.arb index 87bb234..37a1f63 100644 --- a/lib/l10n/intl_eo.arb +++ b/lib/l10n/intl_eo.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Ne rajtas redakti la privatan mesaĝon.", "post_title_too_long": "Titolo de afiŝo estas tro longa.", "email_already_exists": "Retpoŝtadreso jam ekzistas.", - "user_already_exists": "Uzanto jam ekzistas." + "user_already_exists": "Uzanto jam ekzistas.", + "number_users_online": "{count,plural, =1{{count} uzanto enreta} other{{count} uzantoj enretaj}}" } diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index 6695141..88268ad 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Sin permisos para editar el mensaje privado.", "post_title_too_long": "El título de la publicación es muy largo.", "email_already_exists": "El correo ya está en uso.", - "user_already_exists": "El usuario ya existe." + "user_already_exists": "El usuario ya existe.", + "number_users_online": "{count,plural, =1{{count} usuario en línea} other{{count} usuarios en línea}}" } diff --git a/lib/l10n/intl_eu.arb b/lib/l10n/intl_eu.arb index 477e469..227b20b 100644 --- a/lib/l10n/intl_eu.arb +++ b/lib/l10n/intl_eu.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Ezin duzu mezu pribaturik editatu.", "post_title_too_long": "Bidalketaren izenburua luzeegia da.", "email_already_exists": "Eposta hori dagoeneko existitzen da.", - "user_already_exists": "Erabiltzaile hori dagoeneko existitzen da." + "user_already_exists": "Erabiltzaile hori dagoeneko existitzen da.", + "number_users_online": "{count,plural, =1{Erabiltzaile {count} konektatuta} other{{count} erabiltzaile konektatuta}}" } diff --git a/lib/l10n/intl_fa.arb b/lib/l10n/intl_fa.arb index 099e506..db9f2dd 100644 --- a/lib/l10n/intl_fa.arb +++ b/lib/l10n/intl_fa.arb @@ -67,5 +67,6 @@ "couldnt_update_user": "ناتوانی در به‌روزرسانی کاربر.", "couldnt_update_post": "ناتوای در به‌روزرسانی مطلب", "email_already_exists": "این رایانامه از قبل وجود دارد.", - "user_already_exists": "این کاربر از قبل وجود دارد." + "user_already_exists": "این کاربر از قبل وجود دارد.", + "number_users_online": "{count,plural, =1{{count} کاربر برخط}}" } diff --git a/lib/l10n/intl_fi.arb b/lib/l10n/intl_fi.arb index 6ca957e..a0de713 100644 --- a/lib/l10n/intl_fi.arb +++ b/lib/l10n/intl_fi.arb @@ -90,5 +90,6 @@ "no_private_message_edit_allowed": "Sinulla ei ole oikeutta muokata yksityisviestiä.", "post_title_too_long": "Viestin otsikko on liian pitkä.", "email_already_exists": "Sähköposti on jo olemassa.", - "user_already_exists": "Käyttäjä on jo olemassa." + "user_already_exists": "Käyttäjä on jo olemassa.", + "number_users_online": "{count,plural, =1{{count} käyttäjä aktiivisena} other{{count} käyttäjää aktiivisena}}" } diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 7034f5b..bc1f11e 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -104,5 +104,6 @@ "no_private_message_edit_allowed": "Pas autorisé à modifier un message privé.", "post_title_too_long": "Le titre de la publication est trop long.", "email_already_exists": "L’email existe déjà.", - "user_already_exists": "L’utilisateur·rice existe déjà." + "user_already_exists": "L’utilisateur·rice existe déjà.", + "number_users_online": "{count,plural, =1{{count} Utilisateur en ligne} other{{count} Utilisateurs en ligne}}" } diff --git a/lib/l10n/intl_hu.arb b/lib/l10n/intl_hu.arb index dc136d6..ae0c085 100644 --- a/lib/l10n/intl_hu.arb +++ b/lib/l10n/intl_hu.arb @@ -91,5 +91,6 @@ "no_private_message_edit_allowed": "A privát üzenet szerkesztése nem engedélyezett.", "post_title_too_long": "A bejegyzés címe túl hosszú.", "email_already_exists": "Az email már létezik.", - "user_already_exists": "A felhasználó már létezik." + "user_already_exists": "A felhasználó már létezik.", + "number_users_online": "{count,plural, =1{{count} online felhasználó} other{{count} online felhasználó}}" } diff --git a/lib/l10n/intl_it.arb b/lib/l10n/intl_it.arb index 0dc8aab..4d22c70 100644 --- a/lib/l10n/intl_it.arb +++ b/lib/l10n/intl_it.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Non hai i permessi per modificare un messaggio privato.", "post_title_too_long": "Titolo della pubblicazione troppo lungo.", "email_already_exists": "Indirizzo email già presente.", - "user_already_exists": "L'utente esiste già." + "user_already_exists": "L'utente esiste già.", + "number_users_online": "{count,plural, =1{{count} utente connesso} other{{count} utenti connessi}}" } diff --git a/lib/l10n/intl_ja.arb b/lib/l10n/intl_ja.arb index 6d87fed..89dd062 100644 --- a/lib/l10n/intl_ja.arb +++ b/lib/l10n/intl_ja.arb @@ -93,5 +93,6 @@ "no_private_message_edit_allowed": "プライベートメッセージの編集許可がありません。", "post_title_too_long": "投稿のタイトルが長すぎます。", "email_already_exists": "メールアドレスが既に使用されています。", - "user_already_exists": "ユーザーは既に存在します。" + "user_already_exists": "ユーザーは既に存在します。", + "number_users_online": "{count,plural, =1{{count} 名のユーザーがオンライン}}" } diff --git a/lib/l10n/intl_ka.arb b/lib/l10n/intl_ka.arb index 52d228e..38cbbaf 100644 --- a/lib/l10n/intl_ka.arb +++ b/lib/l10n/intl_ka.arb @@ -86,5 +86,6 @@ "couldnt_update_post": "პოსტი ვერ განახლდა", "post_title_too_long": "პოსტის სათაური ძალიან გრძელია.", "email_already_exists": "ელ-პოსტა უკვე არსებობს.", - "user_already_exists": "მომხმარებელი უკვე არსებობს." + "user_already_exists": "მომხმარებელი უკვე არსებობს.", + "number_users_online": "{count,plural, =1{მომხმარებელი საიტზე} other{მომხმარებელი საიტზე}}" } diff --git a/lib/l10n/intl_ko.arb b/lib/l10n/intl_ko.arb index 27d5149..53eec0d 100644 --- a/lib/l10n/intl_ko.arb +++ b/lib/l10n/intl_ko.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "개인 메시지를 편집 할 수 없습니다.", "post_title_too_long": "게시물 제목이 너무 깁니다.", "email_already_exists": "이메일이 이미 존재합니다.", - "user_already_exists": "사용자가 이미 존재합니다." + "user_already_exists": "사용자가 이미 존재합니다.", + "number_users_online": "{count,plural, =1{접속자수 {count}}}" } diff --git a/lib/l10n/intl_nl.arb b/lib/l10n/intl_nl.arb index 214d4d2..922c1b7 100644 --- a/lib/l10n/intl_nl.arb +++ b/lib/l10n/intl_nl.arb @@ -91,5 +91,6 @@ "no_private_message_edit_allowed": "Niet toegestaan om privé berichten te wijzigen.", "post_title_too_long": "Posttitel te lang.", "email_already_exists": "Email bestaat al.", - "user_already_exists": "Gebruiker bestaat al." + "user_already_exists": "Gebruiker bestaat al.", + "number_users_online": "{count,plural, =1{{count} gebruiker online} other{{count} gebruikers online}}" } diff --git a/lib/l10n/intl_pt_BR.arb b/lib/l10n/intl_pt_BR.arb index ec34479..420e1a7 100644 --- a/lib/l10n/intl_pt_BR.arb +++ b/lib/l10n/intl_pt_BR.arb @@ -101,5 +101,6 @@ "no_private_message_edit_allowed": "Sem permissão para editar mensagem privada.", "post_title_too_long": "Título da publicação muito longo.", "email_already_exists": "Este e-mail já existe.", - "user_already_exists": "Este usuário já existe." + "user_already_exists": "Este usuário já existe.", + "number_users_online": "{count,plural, =1{{count} usuário online} other{{count} usuários online}}" } diff --git a/lib/l10n/intl_sq.arb b/lib/l10n/intl_sq.arb index a6a05a1..d618a25 100644 --- a/lib/l10n/intl_sq.arb +++ b/lib/l10n/intl_sq.arb @@ -91,5 +91,6 @@ "no_private_message_edit_allowed": "Nuk lejohet redaktimi i mesazhit privat.", "post_title_too_long": "Titulli i postimit ishte shumë i gjatë.", "email_already_exists": "Email-i tashmë ekziston.", - "user_already_exists": "Përdoruesi tashmë ekziston." + "user_already_exists": "Përdoruesi tashmë ekziston.", + "number_users_online": "{count,plural, =1{{count} Përdorues Online} other{{count} Përdoruesa Online}}" } diff --git a/lib/l10n/intl_sv.arb b/lib/l10n/intl_sv.arb index 2b655c1..e108622 100644 --- a/lib/l10n/intl_sv.arb +++ b/lib/l10n/intl_sv.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "Inte tillåtet att redigera privata meddelanden.", "post_title_too_long": "Inläggstiteln är för lång.", "email_already_exists": "E-post finns redan.", - "user_already_exists": "Användaren finns redan." + "user_already_exists": "Användaren finns redan.", + "number_users_online": "{count,plural, =1{{count} användare inloggad} other{{count} användare inloggade}}" } diff --git a/lib/l10n/intl_tr.arb b/lib/l10n/intl_tr.arb index b5da831..b2d9425 100644 --- a/lib/l10n/intl_tr.arb +++ b/lib/l10n/intl_tr.arb @@ -91,5 +91,6 @@ "no_private_message_edit_allowed": "Şahsa özel mesajı düzenlemek mümkün değil.", "post_title_too_long": "Paylaşım başlığı çok uzun.", "email_already_exists": "Böyle bir e-mail adresi zaten var.", - "user_already_exists": "Böyle bir kullanıcı zaten var." + "user_already_exists": "Böyle bir kullanıcı zaten var.", + "number_users_online": "{count,plural, =1{{count} Kullanıcı Hatta} other{{count} Kullanıcı Hatta}}" } diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index daa3acf..137e12a 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -105,5 +105,6 @@ "no_private_message_edit_allowed": "没有编辑私信的权限。", "post_title_too_long": "帖子标题过长。", "email_already_exists": "邮箱已占用.", - "user_already_exists": "用户已存在。" + "user_already_exists": "用户已存在。", + "number_users_online": "{count,plural, =1{{count} 在线用户} other{{count} 名在线用户}}" } diff --git a/lib/l10n/l10n_from_string.dart b/lib/l10n/l10n_from_string.dart index 7164f96..191356b 100644 --- a/lib/l10n/l10n_from_string.dart +++ b/lib/l10n/l10n_from_string.dart @@ -124,6 +124,7 @@ abstract class L10nStrings { static const post_title_too_long = 'post_title_too_long'; static const email_already_exists = 'email_already_exists'; static const user_already_exists = 'user_already_exists'; + static const number_users_online = 'number_users_online'; } extension L10nFromString on String { diff --git a/lib/l10n/untranslated.json b/lib/l10n/untranslated.json index 2cbf4ff..00d4b98 100644 --- a/lib/l10n/untranslated.json +++ b/lib/l10n/untranslated.json @@ -50,7 +50,9 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "number_users_online" ], "ca": [ @@ -182,7 +184,8 @@ "bio_length_overflow", "couldnt_update_private_message", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long" ], "fi": [ @@ -232,7 +235,8 @@ "report_reason_required", "report_too_long", "couldnt_create_report", - "couldnt_resolve_report" + "couldnt_resolve_report", + "number_users_online" ], "gl": [ @@ -345,7 +349,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "hi": [ @@ -440,7 +448,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "hr": [ @@ -553,7 +565,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "hu": [ @@ -751,7 +767,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "ko": [ @@ -898,7 +918,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "pl": [ @@ -906,7 +930,8 @@ "appearance", "add_instance", "sign_in", - "register" + "register", + "number_users_online" ], "pt": [ @@ -1019,7 +1044,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "pt_BR": [ @@ -1043,7 +1072,8 @@ "appearance", "add_instance", "sign_in", - "register" + "register", + "number_users_online" ], "sq": [ @@ -1180,7 +1210,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "sr_Latn": [ @@ -1274,7 +1308,11 @@ "couldnt_update_private_message", "couldnt_update_post", "couldnt_create_private_message", - "no_private_message_edit_allowed" + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" ], "sv": [ @@ -1287,6 +1325,123 @@ "register" ], + "th": [ + "add_account", + "select_instance", + "accounts", + "appearance", + "add_instance", + "sign_in", + "register", + "settings", + "password", + "email_or_username", + "posts", + "comments", + "modlog", + "community", + "url", + "title", + "body", + "nsfw", + "post", + "save", + "send_message", + "subscribed", + "local", + "all", + "replies", + "mentions", + "from", + "to", + "deleted_by_creator", + "more", + "mark_as_read", + "mark_as_unread", + "reply", + "edit", + "delete", + "restore", + "yes", + "no", + "avatar", + "banner", + "display_name", + "bio", + "email", + "matrix_user", + "sort_type", + "type", + "show_nsfw", + "send_notifications_to_email", + "delete_account", + "saved", + "communities", + "users", + "theme", + "language", + "hot", + "new_", + "old", + "top", + "chat", + "admin", + "by", + "not_an_admin", + "couldnt_find_post", + "not_logged_in", + "site_ban", + "community_ban", + "downvotes_disabled", + "invalid_url", + "locked", + "couldnt_create_comment", + "couldnt_like_comment", + "couldnt_update_comment", + "no_comment_edit_allowed", + "couldnt_save_comment", + "couldnt_get_comments", + "report_reason_required", + "report_too_long", + "couldnt_create_report", + "couldnt_resolve_report", + "invalid_post_title", + "couldnt_create_post", + "couldnt_like_post", + "couldnt_find_community", + "couldnt_get_posts", + "no_post_edit_allowed", + "couldnt_save_post", + "site_already_exists", + "couldnt_update_site", + "invalid_community_name", + "community_already_exists", + "community_moderator_already_exists", + "community_follower_already_exists", + "not_a_moderator", + "couldnt_update_community", + "no_community_edit_allowed", + "system_err_login", + "community_user_already_banned", + "couldnt_find_that_username_or_email", + "password_incorrect", + "registration_closed", + "invalid_password", + "passwords_dont_match", + "captcha_incorrect", + "invalid_username", + "bio_length_overflow", + "couldnt_update_user", + "couldnt_update_private_message", + "couldnt_update_post", + "couldnt_create_private_message", + "no_private_message_edit_allowed", + "post_title_too_long", + "email_already_exists", + "user_already_exists", + "number_users_online" + ], + "tr": [ "add_account", "select_instance", @@ -1332,7 +1487,8 @@ "not_a_moderator", "invalid_password", "captcha_incorrect", - "bio_length_overflow" + "bio_length_overflow", + "number_users_online" ], "zh": [ diff --git a/scripts/gen_l10n_from_string.dart b/scripts/gen_l10n_from_string.dart index 2d7b75d..720596d 100644 --- a/scripts/gen_l10n_from_string.dart +++ b/scripts/gen_l10n_from_string.dart @@ -10,6 +10,12 @@ Future main(List args) async { as Map; final keys = strings.keys.where((key) => !key.startsWith('@')).toSet(); + final keysWithoutVariables = keys.where((key) { + final metadata = strings['@$key'] as Map; + final placeholders = metadata['placeholders'] as Map; + + return placeholders?.isEmpty ?? true; + }).toSet(); await File('lib/l10n/l10n_from_string.dart').writeAsString('''$autoGenHeader // ignore_for_file: constant_identifier_names @@ -24,7 +30,7 @@ ${keys.map((key) => " static const $key = '$key';").join('\n')} extension L10nFromString on String { String tr(BuildContext context) { switch (this) { -${keys.map((key) => " case L10nStrings.$key:\n return L10n.of(context).$key;").join('\n')} +${keysWithoutVariables.map((key) => " case L10nStrings.$key:\n return L10n.of(context).$key;").join('\n')} default: return this; diff --git a/scripts/migrate_lemmy_l10n.dart b/scripts/migrate_lemmy_l10n.dart index 4db746c..f613572 100644 --- a/scripts/migrate_lemmy_l10n.dart +++ b/scripts/migrate_lemmy_l10n.dart @@ -115,8 +115,12 @@ const toExtract = { 'post_title_too_long': null, 'email_already_exists': null, 'user_already_exists': null, + 'number_online': 'number_users_online', }; +// TODO: migrate those with changed capitalization +// 'number_of_comments': null, + const repoName = 'lemmy-translations'; const baseLanguage = 'en'; const flutterIntlPrefix = 'intl_'; @@ -210,17 +214,48 @@ void portStrings( printError('"$key" does not exist in $repoName'); } - if (lemmurTranslations[baseLanguage].containsKey(key) && !force) { + if (lemmurTranslations[baseLanguage].containsKey(renamedKey) && !force) { confirm('"$key" already exists in lemmur, overwrite?'); } + final metadata = {}; + // ignore: omit_local_variable_types + String Function(Map translations) transformer = + (translations) => translations[key]; + + // check if it has a plural form + if (lemmyTranslations[baseLanguage].containsKey('${key}_plural')) { + final variable = RegExp(r'{([\w_]+)}') + .firstMatch(lemmyTranslations[baseLanguage][key]) + .group(1); + + transformer = (translations) { + if (translations[key] == null) return null; + + final fixedVariables = + translations[key].replaceAll('{{$variable}}', '{$variable}'); + + final pluralForm = () { + if (translations.containsKey('${key}_plural')) { + return translations['${key}_plural'] + .replaceAll('{{$variable}}', '{$variable}'); + } + + return null; + }(); + + return '{$variable,plural, =1{$fixedVariables}${pluralForm != null ? ' other{$pluralForm}' : ''}}'; + }; + metadata['placeholders'] = {variable: {}}; + } + for (final trans in lemmyTranslations.entries) { final language = trans.key; final strings = trans.value; - lemmurTranslations[language][renamedKey] = strings[key]; + lemmurTranslations[language][renamedKey] = transformer(strings); } - lemmurTranslations[baseLanguage]['@$renamedKey'] = {}; + lemmurTranslations[baseLanguage]['@$renamedKey'] = metadata; } }