Skip to content

Commit

Permalink
Changed meta key to ↞ [auto-sync from adamlui/python-utils]
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui authored and kudo-sync-bot committed Apr 29, 2024
1 parent 05a8102 commit 6fea322
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions utils/translate-en-messages.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
'''
Script: translate-en-messages.py
Version: 2024.4.29.1
Version: 2024.4.29.4
Description: Translate msg's from en/messages.json to [[output_langs]/messages.json]
Author: Adam Lui
URL: https://github.com/adamlui/python-utils
Homepage: https://github.com/adamlui/python-utils
'''

import os, json
from sys import stdout # for dynamic prints
from translate import Translator

locales_folder = '_locales' ; provider = ''
target_langs = ['af', 'am', 'ar', 'az', 'be', 'bem', 'bg', 'bn', 'bo', 'bs', 'ca', 'ceb', 'ckb', 'cs', 'cy', 'da', 'de', 'dv', 'dz', 'el', 'en', 'en-GB', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr', 'gd', 'gl', 'gu', 'haw', 'he', 'hi', 'hr', 'ht', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'ka', 'kab', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'la', 'lb', 'lo', 'lt', 'lv', 'mg', 'mi', 'mk', 'ml', 'mn', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'ny', 'pa', 'pap', 'pl', 'ps', 'pt', 'ro', 'ru', 'rw', 'sg', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tn', 'to', 'tpi', 'tr', 'uk', 'ur', 'uz', 'vi', 'xh', 'yi', 'zh', 'zh-CN', 'zh-HK', 'zh-SG', 'zh-TW', 'zu']

# UI initializations
terminal_width = os.get_terminal_size()[0]
def print_trunc(msg) : print(msg if len(msg) < terminal_width else msg[0:terminal_width-4] + '...')
def print_trunc(msg, end='\n') : print(msg if len(msg) < terminal_width else msg[0:terminal_width-4] + '...', end=end)
def overwrite_print(msg) : stdout.write('\r' + msg.ljust(terminal_width)[:terminal_width])

print('')

Expand Down Expand Up @@ -87,7 +89,8 @@ def print_trunc(msg) : print(msg if len(msg) < terminal_width else msg[0:termina
else : messages = {}

# Attempt translations
print(f"{ 'Adding' if not messages else 'Updating' } { folder }/messages.json...", end='\r')
print_trunc(f"{ 'Adding' if not messages else 'Updating' } { folder }/messages.json...", end='')
stdout.flush()
en_keys = list(en_messages.keys())
fail_flags = ['INVALID TARGET LANGUAGE', 'TOO MANY REQUESTS', 'MYMEMORY']
for key in en_keys:
Expand Down Expand Up @@ -122,7 +125,7 @@ def print_trunc(msg) : print(msg if len(msg) < terminal_width else msg[0:termina
if translated_msgs == messages : langs_skipped.append(lang_code) ; lang_skipped = True
elif translated_msgs != messages : langs_translated.append(lang_code) ; lang_translated = True
if not lang_translated : langs_not_translated.append(lang_code)
print(f"{ 'Added' if lang_added else 'Skipped' if lang_skipped else 'Updated' } { folder }/messages.json")
overwrite_print(f"{ 'Added' if lang_added else 'Skipped' if lang_skipped else 'Updated' } { folder }/messages.json")

# Print final summary
print_trunc('\nAll messages.json files updated successfully!\n')
Expand Down

0 comments on commit 6fea322

Please sign in to comment.