From 4366f8e5d820e3517573c9d342faefe489d04aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 22 Jan 2024 10:01:02 +0000 Subject: [PATCH] Remove incorrect translations, improve script --- app/config/locale/translations/as.json | 14 +------ app/config/locale/translations/be.json | 14 +------ app/config/locale/translations/bh.json | 14 +------ app/config/locale/translations/la.json | 14 +------ app/config/locale/translations/ml.json | 14 +------ app/config/locale/translations/nn.json | 14 +------ app/config/locale/translations/sd.json | 14 +------ .../Tasks/DevGenerateTranslations.php | 41 +++++++++++++++---- 8 files changed, 41 insertions(+), 98 deletions(-) diff --git a/app/config/locale/translations/as.json b/app/config/locale/translations/as.json index 0d4998adf3..31809f2bbd 100644 --- a/app/config/locale/translations/as.json +++ b/app/config/locale/translations/as.json @@ -228,17 +228,5 @@ "continents.eu": "ইউৰোপ", "continents.na": "উত্তৰ আমেৰিকা", "continents.oc": "ওচেনিয়া", - "continents.sa": "দক্ষিণ আমেৰিকা", - "emails.magicSession.optionButton": "Bấm vào nút bên dưới để đăng nhập an toàn vào tài khoản {{project}} của bạn. Nó sẽ hết hạn trong 1 giờ.", - "emails.magicSession.buttonText": "Inngå á {{project}}", - "emails.magicSession.clientInfo": "I'm sorry, but you haven't provided the specific language associated with a country code for translation, and \"as\" doesn't correspond to any current ISO country code. Could you please clarify the target language you want the translation in?", - "emails.certificate.subject": "In the context of your request, it is not entirely clear what the country code \"as\" refers to. However, \"AS\" is often used as the country code for American Samoa, where the primary language is English. If you meant another \"as\" for a specific language, please provide clarification. If you did mean American Samoa, the translation would remain the same as the original text:\n\nCertificate failure for %s", - "emails.certificate.hello": "Since you haven't specified which country \"as\" refers to, I can't provide a translation. If you could provide the name of the country or another form of the country code, that would be very helpful.", - "emails.certificate.body": "Beklagar, men det är inte tillräckligt med information för att avgöra vilket lands specifika språk som avses med landskoden \"as\". \"AS\" kan antingen avse Amerikanska Samoa, vars officiella språk är engelska och samoanska, eller det kan avse en generell landskod. Om du kan ge mer information eller specificera ett land, kan jag ge en exakt översättning.", - "emails.certificate.footer": "Since you haven't specified the target language and only provided the country code \"as,\" which refers to American Samoa, where English and Samoan are the official languages, I will translate it into Samoan:\n\nO lau tusi pasi ua mavae o le a talafeagai mo aso e 30 talu ona tupu le tulaga muamua le manuia. Matou te fautuaina malosi le su'esu'e i lenei mataupu, a leai o le a leai sau vaega e iai se SSL fa'amaoniga talafeagai.", - "emails.certificate.thanks": "The language of the country with the country code \"AS\" which stands for American Samoa is primarily Samoan. The translation of \"Thanks\" in Samoan is:\n\nFa'afetai", - "emails.certificate.signature": "I'm sorry, but to provide a translation into the target language, I need to know the specific language you're referring to with the country code \"as.\" The country code \"AS\" is generally used for American Samoa, where the languages spoken are English and Samoan. If you need a translation into Samoan, please confirm, and I will proceed with the translation.", - "sms.verification.body": "{{secret}} er din {{project}} verifikasjonskode.", - "emails.magicSession.securityPhrase": "I apologize, but it appears there might be a misunderstanding with the country code provided. The country code \"as\" commonly refers to American Samoa, and the languages spoken there are English and Samoan. If translation into Samoan is desired, here it is:\n\nO le upu fa'amau mo lenei imeli o {{phrase}}. E mafai ona e talitonu i lenei imeli pe afai e ōgatusa le upu lea ma le upu na fa'aalia i le taimi o le saini i totonu.", - "emails.magicSession.optionUrl": "There appears to be a misunderstanding. The country code \"as\" is associated with American Samoa, where the primary language is English. Therefore, the translation would remain the same as English:\n\nIf you are unable to sign in using the button above, please visit the following link:" + "continents.sa": "দক্ষিণ আমেৰিকা" } \ No newline at end of file diff --git a/app/config/locale/translations/be.json b/app/config/locale/translations/be.json index 9ae999198f..5c94b8870a 100644 --- a/app/config/locale/translations/be.json +++ b/app/config/locale/translations/be.json @@ -228,17 +228,5 @@ "continents.eu": "Еўропа", "continents.na": "Паўночная Амерыка", "continents.oc": "Акіянія", - "continents.sa": "Паўднёвая Амерыка", - "emails.magicSession.optionButton": "Клікніце кнопку ніжэй, каб бяспечна ўвайсці ў свой рахунак {{project}}. Ён скончыцца праз 1 гадзіну.", - "emails.magicSession.buttonText": "Aanmelden bij {{project}}", - "emails.magicSession.clientInfo": "Als u niet om de aanmelding heeft gevraagd, kunt u deze e-mail gerust negeren.", - "emails.certificate.subject": "The country code BE refers to Belgium, which has three official languages: Dutch, French, and German. Please specify which language you would like the translation in.", - "emails.certificate.hello": "To provide you with the correct translation, I need to clarify the country code \"be\" you mentioned. It might refer to Belgium, which has three official languages: Dutch, French, and German. \n\nPlease specify which language you would like me to translate \"Hello\" into: Dutch, French, or German.", - "emails.certificate.body": "Certificaat voor uw domein '{{domain}}' kon niet worden gegenereerd. Dit is poging nr. {{attempt}}, en de fout werd veroorzaakt door: {{error}}", - "emails.certificate.footer": "Ваш папярэдні сертыфікат будзе дзейнічаць 30 дзён з моманту першай няўдачы. Мы вельмі рэкамендуем разабрацца ў гэтай сітуацыі, інакш ваш дамен застанецца без дзейнага сертыфіката SSL забеспячэння.", - "emails.certificate.thanks": "The country code BE stands for Belgium, where there are two main languages spoken: Dutch and French. Since you did not specify the language, I will provide the translation in both:\n\nDutch: Dank je\nFrench: Merci", - "emails.certificate.signature": "{{project}} équipe", - "sms.verification.body": "{{secret}} ist Ihr Verifizierungscode für {{project}}.", - "emails.magicSession.securityPhrase": "De beveiligingszin voor deze e-mail is {{phrase}}. U kunt deze e-mail vertrouwen als deze zin overeenkomt met de zin die getoond wordt bij het aanmelden.", - "emails.magicSession.optionUrl": "Si vous n'arrivez pas à vous connecter en utilisant le bouton ci-dessus, veuillez visiter le lien suivant :" + "continents.sa": "Паўднёвая Амерыка" } \ No newline at end of file diff --git a/app/config/locale/translations/bh.json b/app/config/locale/translations/bh.json index 6946578869..edbc15c28c 100644 --- a/app/config/locale/translations/bh.json +++ b/app/config/locale/translations/bh.json @@ -228,17 +228,5 @@ "continents.eu": "यूरोप", "continents.na": "उत्तरी अमेरिका", "continents.oc": "ओशिनिया", - "continents.sa": "दक्षिण अमेरिका", - "emails.magicSession.optionButton": "Klike sou bouton ki pi ba a pou ou konekte an sekirite nan kont {{project}} ou. Li ap ekspire nan 1 è.", - "emails.magicSession.buttonText": "There might be some confusion here, as there is no specific language associated with the country code \"bh,\" which stands for Bahrain. The primary language spoken in Bahrain is Arabic. Assuming you are asking for a translation into Arabic, the translation would be:\n\nتسجيل الدخول إلى {{project}}", - "emails.magicSession.clientInfo": "Sorry, but I cannot provide the translation as \"bh\" is not a recognized ISO language code and does not correspond to any specific language. Please provide a valid language or country code for translation.", - "emails.certificate.subject": "लिए प्रमाणपत्र असफलता %s", - "emails.certificate.hello": "Namaste", - "emails.certificate.body": "Sorry, I am unable to provide the translation as there is no language associated with the country code \"bh.\" \"BH\" is the country code for Bahrain, where the official language is Arabic. Please provide specific instructions for the target language if Arabic translation is required.", - "emails.certificate.footer": "साँचे सर्टिफिकेट 30 दिन तक मान्य होता, पहिलका असफलता के बाद। हमनी के राउर से जोर देके कहतानी कि एह मामला के जांच करीं, ना त राउर डोमेन बिना जायज SSL संवाद के रह जाई.", - "emails.certificate.thanks": "धन्यवाद", - "emails.certificate.signature": "تیم {{project}}", - "sms.verification.body": "{{secret}} هو رمز التحقق الخاص ب{{project}} الخاص بك.", - "emails.magicSession.securityPhrase": "La frase de seguridad para este correo electrónico es {{phrase}}. Puedes confiar en este correo electrónico si esta frase coincide con la frase mostrada durante el inicio de sesión.", - "emails.magicSession.optionUrl": "Yadi aap uppar diye gaye button ka upayog karke sign in nahi kar pa rahe hain, toh kripaya is link ka anusaran karein:" + "continents.sa": "दक्षिण अमेरिका" } \ No newline at end of file diff --git a/app/config/locale/translations/la.json b/app/config/locale/translations/la.json index b09b2f109c..f27558b5fc 100644 --- a/app/config/locale/translations/la.json +++ b/app/config/locale/translations/la.json @@ -228,17 +228,5 @@ "continents.eu": "Europe", "continents.na": "America del Norte", "continents.oc": "Oceania", - "continents.sa": "America del Sur", - "emails.magicSession.optionButton": "Preme el boton infra pro signar securmente in tu conto de {{project}}. Illo expirara in 1 hora.", - "emails.magicSession.buttonText": "Inicia sesión en {{project}}", - "emails.magicSession.clientInfo": "Esta conexión fue solicitada usando {{agentClient}} en {{agentDevice}} {{agentOs}}. Si usted no solicitó la conexión, puede ignorar este correo electrónico de forma segura.", - "emails.certificate.subject": "Fracaso del certificado para %s", - "emails.certificate.hello": "There seems to be a misunderstanding. The country code \"LA\" refers to Laos, and the primary language used there is Lao. However, without specific instructions to translate into Lao, I cannot proceed with the translation. If Lao is indeed the intended language, please confirm, and I will provide you with the translation.", - "emails.certificate.body": "El certificado para su dominio '{{domain}}' no pudo ser generado. Este es el intento número {{attempt}}, y el fallo fue causado por: {{error}}.", - "emails.certificate.footer": "Su certificado anterior será válido por 30 días desde el primer fallo. Recomendamos encarecidamente investigar este caso, de lo contrario su dominio quedará sin una comunicación SSL válida.", - "emails.certificate.thanks": "Gracias", - "emails.certificate.signature": "{{project}} equipo", - "sms.verification.body": "{{secret}} ແມ່ນລະຫັດຢືນຢັນສໍາລັບ {{project}} ຂອງທ່ານ.", - "emails.magicSession.securityPhrase": "La locución de seguridat pro iste correo es {{phrase}}. Podes confiar en iste correo si esta locución coincidit con la locución amostrada durante el ingreso.", - "emails.magicSession.optionUrl": "Si no puedes iniciar sesión utilizando el botón de arriba, por favor visita el siguiente enlace:" + "continents.sa": "America del Sur" } \ No newline at end of file diff --git a/app/config/locale/translations/ml.json b/app/config/locale/translations/ml.json index c577239a31..7fcaf77fba 100644 --- a/app/config/locale/translations/ml.json +++ b/app/config/locale/translations/ml.json @@ -228,17 +228,5 @@ "continents.eu": "യൂറോപ്പ്", "continents.na": "വടക്കേ അമേരിക്ക", "continents.oc": "ഓഷ്യാനിയ", - "continents.sa": "തെക്കേ അമേരിക്ക", - "emails.magicSession.optionButton": "ಕೆಳಗಿನ ಬಟನ್ ಒತ್ತಿ ನಿಮ್ಮ {{project}} ಖಾತೆಗೆ ಸುರಕ್ಷಿತವಾಗಿ ಸೈನ್ ಇನ್ ಮಾಡಿ. ಇದು 1 ಗಂಟೆಯಲ್ಲಿ ಅವಧಿ ಮುಗಿಯುವುದು.", - "emails.magicSession.buttonText": "Se connecter à {{project}}", - "emails.magicSession.clientInfo": "I'm sorry, but there appears to be some confusion. The country code \"ml\" stands for Mali, where the official language is French. However, many local languages such as Bambara are also widely spoken. Please specify if you would like the translation in French or any other specific local language.", - "emails.certificate.subject": "Tsy fahombiazan'ny fahaizana ho an'ny %s", - "emails.certificate.hello": "Bonjour", - "emails.certificate.body": "നിങ്ങളുടെ ഡൊമെയ്‌ൻ '{{domain}}'നായുള്ള സർട്ടിഫിക്കറ്റ് ഉണ്ടാക്കാൻ കഴിയിച്ചില്ല. ഇത് ശ്രമമായ {{attempt}} ആണ്, പരാജയത്തിനു കാരണം: {{error}}", - "emails.certificate.footer": "Ny zom-pokotaninao teo aloha dia hanan-kery mandritra ny 30 andro manomboka amin'ny tsy fahombiazana voalohany. Izahay dia manoro hevitra mafy ny hanaovana fikarohana momba ity tranga ity, raha tsy izany ny sehatra misy anao dia ho tonga amin'ny toerana tsy misy fifandraisana SSL manan-kery.", - "emails.certificate.thanks": "Merci", - "emails.certificate.signature": "{{project}} ekipi", - "sms.verification.body": "{{secret}} tànna {{project}} ka càddu jamiilu la.", - "emails.magicSession.securityPhrase": "ഈ ഇമെയിലിന്റെ സുരക്ഷാ വാചകം {{phrase}} ആണ്. സൈൻ ഇൻ ചെയ്യുമ്പോൾ കാണിച്ച വാചകവുമായി ഈ വാചകം ഒത്തുപോകുന്നെങ്കിൽ ഈ ഇമെയിലിനെ വിശ്വസിക്കാം.", - "emails.magicSession.optionUrl": "Raha toa ka tsy afaka miditra ianao amin'ny alàlan'ny bokotra etsy ambony, azafady mba tsidiho ity rohy manaraka ity:" + "continents.sa": "തെക്കേ അമേരിക്ക" } \ No newline at end of file diff --git a/app/config/locale/translations/nn.json b/app/config/locale/translations/nn.json index 1391280b5b..52e7dc5ec3 100644 --- a/app/config/locale/translations/nn.json +++ b/app/config/locale/translations/nn.json @@ -228,17 +228,5 @@ "continents.eu": "Europa", "continents.na": "Nord-Amerika", "continents.oc": "Oseania", - "continents.sa": "Sør-Amerika", - "emails.magicSession.optionButton": "Klikk på knappen under for å trygt logge inn på din {{project}}-konto. Den vil utløpe om 1 time.", - "emails.magicSession.buttonText": "Innlogging til {{project}}", - "emails.magicSession.clientInfo": "Denne innloggingen ble forespurt ved hjelp av {{agentClient}} på {{agentDevice}} {{agentOs}}. Hvis du ikke ba om innloggingen, kan du trygt se bort fra denne e-posten.", - "emails.certificate.subject": "Unfortunately, the country code \"nn\" is ambiguous, as it doesn't correspond to a recognized ISO 3166-1 alpha-2 country code. However, “nn” often refers to “Nynorsk,” one of the written standards of the Norwegian language. If you intended to translate the sentence into Nynorsk (Norwegian), here is the translation:\n\n\"Seritifikatsvikt for %s\"", - "emails.certificate.hello": "In order to translate the message to the target language corresponding to the country code \"nn,\" I need to clarify that \"nn\" is not a valid ISO country code. However, if you intended \"nn\" to stand for Nynorsk, which is one of the written standards of the Norwegian language (not to be confused with a country code), then the translation would be:\n\nHallo", - "emails.certificate.body": "Sertifikat for domenet ditt '{{domain}}' kunne ikke genereres. Dette er forsøk nr. {{attempt}}, og mislykkelsen ble forårsaket av: {{error}}", - "emails.certificate.footer": "Ditt førre sertifikat vil vere gyldig i 30 dagar etter den første feilen. Vi rår sterkt til å undersøke denne saka, elles vil domenet ditt ende opp utan ein gyldig SSL-kommunikasjon.", - "emails.certificate.thanks": "The country code \"nn\" provided is not sufficient to determine the target language as it does not correspond to an official ISO 3166-1 alpha-2 country code. Please provide more context or the specific target language you need the translation for.", - "emails.certificate.signature": "{{project}} lag", - "sms.verification.body": "Hemmelig er din prosjekt verifiseringskode.", - "emails.magicSession.securityPhrase": "For the country code \"nn\", there is no officially designated language. The country code \"NN\" is typically used as a placeholder in documentation for a country that is not specified. Please provide a valid country code or specify the target language for the translation.", - "emails.magicSession.optionUrl": "Dersom du ikkje klarer å logge inn ved å bruke knappen over, kan du gå til følgjande lenke:" + "continents.sa": "Sør-Amerika" } \ No newline at end of file diff --git a/app/config/locale/translations/sd.json b/app/config/locale/translations/sd.json index 4c8059f297..8c9412583a 100644 --- a/app/config/locale/translations/sd.json +++ b/app/config/locale/translations/sd.json @@ -228,17 +228,5 @@ "continents.eu": "يورپ", "continents.na": "اتر آمريڪا", "continents.oc": "اوشينيا", - "continents.sa": "ڏکڻ آمريڪا", - "emails.magicSession.optionButton": "محفوظ طريقہ سے اپنے {{project}} اکاؤنٹ میں داخل ہونے کے لئے نيچے دئے گئے بٹن پر کلک کریں۔ یہ ایک گھنٹے ميں ختم ہو جائے گا۔", - "emails.magicSession.buttonText": "It seems that you're referring to a country code \"sd\" which typically represents Sudan. The official languages in Sudan are Arabic and English. Without specific instruction for Arabic, I will provide the translation in Arabic:\n\nتسجيل الدخول إلى {{project}}", - "emails.magicSession.clientInfo": "هن وقت جي لاڳ ان جي درخواست {{agentClient}} تي ڪئي وئي آهي {{agentDevice}} {{agentOs}} تي. جيڪڏهن توهان کي لاڳ ان جي درخواست نه جي آهي، توهان اهو ایميل نظر انداز ڪري سگهو ٿا.", - "emails.certificate.subject": "شهادة فشل ل %s", - "emails.certificate.hello": "مرحبا", - "emails.certificate.body": "I'm sorry, but there is no country code \"sd.\" If you meant Sudan, the country code is \"SD,\" not lowercase, but the official languages of Sudan are Arabic and English. If you need a translation into Arabic, here is the message:\n\nشهادة لنطاق '{{domain}}' الخاص بك لم تتمكن من التوليد. هذه هي المحاولة رقم {{attempt}}، وكان الفشل بسبب: {{error}}", - "emails.certificate.footer": "سابقه سند توهان جي پهلي ناكامي کان 30 ڏينهن لاءِ موزون آهي. اسان توهان کي پوري قائلي سان گهڻي سفارش ڪنداسين ته هن ڪيس کي تحقيق ڪريو، نه ته توهان جو ڊومين بغير موزون SSL مواصلتي جي حالت ۾ ختم ٿي ويندو.", - "emails.certificate.thanks": "شكرا", - "emails.certificate.signature": "I believe there has been a misunderstanding. The country code \"sd\" refers to Sudan, and the official languages of Sudan are Arabic and English. If you are requesting a translation into Arabic, the phrase \"project team\" would be \"فريق المشروع\". If you need a translation into a different language, please provide the correct language or country code.", - "sms.verification.body": "وڊو is your {{project}} جي تصديق ڪوڊ.", - "emails.magicSession.securityPhrase": "محفوظ جملو آهي هن اي ميل لاءِ {{phrase}}. توهان هن اي ميل تي اعتماد ڪري سگهو ٿا جيڪڏهن اهو جملو توهان کي سائن ان ڪرڻ وقت داخل ٿيل جملي سان ملي ويسي.", - "emails.magicSession.optionUrl": "You have provided \"sd\" as the country code; however, \"sd\" is not a valid ISO 3166-1 alpha-2 country code. If you meant \"sd\" to refer to the Sindhi language code, the translation would be:\n\n\"جيڪڏھن توھان مٿي واريل بٽڪَ جي مدد سان سائن ان ڪرڻ ۾ ناڪام آھيو، ته مھرباني ڪري هيٺيان ديئل لنڪ جو ڏورو قدم چونڊو:\"" + "continents.sa": "ڏکڻ آمريڪا" } \ No newline at end of file diff --git a/src/Appwrite/Platform/Tasks/DevGenerateTranslations.php b/src/Appwrite/Platform/Tasks/DevGenerateTranslations.php index 8250c15302..323005de0b 100644 --- a/src/Appwrite/Platform/Tasks/DevGenerateTranslations.php +++ b/src/Appwrite/Platform/Tasks/DevGenerateTranslations.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Tasks; use Exception; use Utopia\CLI\Console; +use Utopia\Config\Config; use Utopia\Fetch\Client; use Utopia\Platform\Action; use Utopia\Validator\Boolean; @@ -66,11 +67,13 @@ class DevGenerateTranslations extends Action $language = \explode('.', $file)[0]; $translation = $this->generateTranslation($language, $mainJson[$key]); - $json = \json_decode(\file_get_contents($dir . '/' . $file), true); - $json[$key] = $translation; - \file_put_contents($dir . '/' . $file, \json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | 0)); - - Console::success("Generated {$key} for {$language}"); + if(!empty($translation)) { + $json = \json_decode(\file_get_contents($dir . '/' . $file), true); + $json[$key] = $translation; + \file_put_contents($dir . '/' . $file, \json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | 0)); + + Console::success("Generated {$key} for {$language}"); + } } } } @@ -81,6 +84,20 @@ class DevGenerateTranslations extends Action private function generateTranslation(string $targetLanguage, string $enTranslation): string { + $list = Config::getParam('locale-languages'); + foreach ($list as $language) { + if($language['code'] === $targetLanguage) { + $languageObject = $language; + } + } + + if(!isset($languageObject)) { + Console::error("{$targetLanguage} language not found"); + return ''; + } + + $targetLanguageName = $languageObject['name']; + $response = Client::fetch('https://api.openai.com/v1/chat/completions', [ 'content-type' => Client::CONTENT_TYPE_APPLICATION_JSON, 'Authorization' => 'Bearer ' . $this->apiKey @@ -89,7 +106,7 @@ class DevGenerateTranslations extends Action 'messages' => [ [ 'role' => 'system', - 'content' => "Please translate the message user provides from English language to target language. Target language is language of country with country code {$targetLanguage}. Do not translate text inside {{ and }} placeholders. Provide only translated text." + 'content' => "Please translate the message user provides from English language to {$targetLanguageName}. Do not translate text inside {{ and }} placeholders. Provide only translated text." ], [ 'role' => 'user', @@ -104,6 +121,16 @@ class DevGenerateTranslations extends Action throw new Exception($response->getBody() . ' with status code ' . $response->getStatusCode() . ' for language ' . $targetLanguage . ' and message ' . $enTranslation); } - return $body['choices'][0]['message']['content']; + $answer = $body['choices'][0]['message']['content']; + + $failureDetectors = [ 'sorry', 'confusion', 'country code', 'misunderstanding', 'correct', 'clarify', 'specific', 'cannot', 'unable', 'language', 'appears' ]; + + foreach($failureDetectors as $detector) { + if(\str_contains($answer, $detector)) { + Console::error("Translation of '{$enTranslation}' for {$targetLanguage} is incorrect: {$answer}"); + } + } + + return $answer; } }