Add possibility of migrating plural forms

This commit is contained in:
shilangyu 2021-03-02 13:18:10 +01:00
parent 632cea230f
commit 83c12a817c
26 changed files with 265 additions and 40 deletions

View File

@ -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 lapunt és massa llarg.",
"email_already_exists": "Ladreça ja és en ús.",
"user_already_exists": "Lusuari ja existeix."
"user_already_exists": "Lusuari ja existeix.",
"number_users_online": "{count,plural, =1{{count} usuari en línia} other{{count} usuaris en línia}}"
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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} ενεργοί χρήστες}}"
}

View File

@ -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": {}
}
}
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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} کاربر برخط}}"
}

View File

@ -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}}"
}

View File

@ -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": "Lemail existe déjà.",
"user_already_exists": "Lutilisateur·rice existe déjà."
"user_already_exists": "Lutilisateur·rice existe déjà.",
"number_users_online": "{count,plural, =1{{count} Utilisateur en ligne} other{{count} Utilisateurs en ligne}}"
}

View File

@ -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ó}}"
}

View File

@ -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}}"
}

View File

@ -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} 名のユーザーがオンライン}}"
}

View File

@ -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{მომხმარებელი საიტზე}}"
}

View File

@ -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}}}"
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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}}"
}

View File

@ -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} 名在线用户}}"
}

View File

@ -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 {

View File

@ -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": [

View File

@ -10,6 +10,12 @@ Future<void> main(List<String> args) async {
as Map<String, dynamic>;
final keys = strings.keys.where((key) => !key.startsWith('@')).toSet();
final keysWithoutVariables = keys.where((key) {
final metadata = strings['@$key'] as Map<String, dynamic>;
final placeholders = metadata['placeholders'] as Map<String, dynamic>;
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;

View File

@ -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 = <String, dynamic>{};
// ignore: omit_local_variable_types
String Function(Map<String, String> 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;
}
}