|
| 1 | +"""Constants for AI static translation synchronization.""" |
| 2 | + |
| 3 | +# LLM Provider names |
| 4 | +PROVIDER_DEEPL = "deepl" |
| 5 | +PROVIDER_GEMINI = "gemini" |
| 6 | +PROVIDER_MISTRAL = "mistral" |
| 7 | +PROVIDER_OPENAI = "openai" |
| 8 | + |
| 9 | +# Learner-facing frontend applications that require translation |
| 10 | +LEARNER_FACING_APPS = [ |
| 11 | + "frontend-app-learning", |
| 12 | + "frontend-app-learner-dashboard", |
| 13 | + "frontend-app-learner-record", |
| 14 | + "frontend-app-account", |
| 15 | + "frontend-app-profile", |
| 16 | + "frontend-app-authn", |
| 17 | + "frontend-app-catalog", |
| 18 | + "frontend-app-discussions", |
| 19 | + "frontend-component-header", |
| 20 | + "frontend-component-footer", |
| 21 | + "frontend-app-ora", |
| 22 | + "frontend-platform", |
| 23 | +] |
| 24 | + |
| 25 | +# Plural forms configuration for different languages |
| 26 | +# Based on GNU gettext plural forms specification |
| 27 | +# See: https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html |
| 28 | +PLURAL_FORMS = { |
| 29 | + # Languages with no plural forms (nplurals=1) |
| 30 | + "ja": "nplurals=1; plural=0;", # Japanese |
| 31 | + "ko": "nplurals=1; plural=0;", # Korean |
| 32 | + "zh": "nplurals=1; plural=0;", # Chinese (all variants) |
| 33 | + "th": "nplurals=1; plural=0;", # Thai |
| 34 | + "vi": "nplurals=1; plural=0;", # Vietnamese |
| 35 | + "id": "nplurals=1; plural=0;", # Indonesian |
| 36 | + "ms": "nplurals=1; plural=0;", # Malay |
| 37 | + "km": "nplurals=1; plural=0;", # Khmer |
| 38 | + "bo": "nplurals=1; plural=0;", # Tibetan |
| 39 | + # Languages with 2 plural forms: plural=(n != 1) |
| 40 | + "en": "nplurals=2; plural=(n != 1);", # English |
| 41 | + "es": "nplurals=2; plural=(n != 1);", # Spanish (all variants) |
| 42 | + "de": "nplurals=2; plural=(n != 1);", # German |
| 43 | + "el": "nplurals=2; plural=(n != 1);", # Greek |
| 44 | + "it": "nplurals=2; plural=(n != 1);", # Italian |
| 45 | + "pt": "nplurals=2; plural=(n != 1);", # Portuguese (all variants) |
| 46 | + "nl": "nplurals=2; plural=(n != 1);", # Dutch |
| 47 | + "sv": "nplurals=2; plural=(n != 1);", # Swedish |
| 48 | + "da": "nplurals=2; plural=(n != 1);", # Danish |
| 49 | + "no": "nplurals=2; plural=(n != 1);", # Norwegian |
| 50 | + "nb": "nplurals=2; plural=(n != 1);", # Norwegian Bokmål |
| 51 | + "nn": "nplurals=2; plural=(n != 1);", # Norwegian Nynorsk |
| 52 | + "fi": "nplurals=2; plural=(n != 1);", # Finnish |
| 53 | + "is": "nplurals=2; plural=(n != 1);", # Icelandic |
| 54 | + "et": "nplurals=2; plural=(n != 1);", # Estonian |
| 55 | + "lv": "nplurals=2; plural=(n != 1);", # Latvian |
| 56 | + "he": "nplurals=2; plural=(n != 1);", # Hebrew |
| 57 | + "hi": "nplurals=2; plural=(n != 1);", # Hindi |
| 58 | + "bn": "nplurals=2; plural=(n != 1);", # Bengali |
| 59 | + "gu": "nplurals=2; plural=(n != 1);", # Gujarati |
| 60 | + "kn": "nplurals=2; plural=(n != 1);", # Kannada |
| 61 | + "ml": "nplurals=2; plural=(n != 1);", # Malayalam |
| 62 | + "ta": "nplurals=2; plural=(n != 1);", # Tamil |
| 63 | + "te": "nplurals=2; plural=(n != 1);", # Telugu |
| 64 | + "or": "nplurals=2; plural=(n != 1);", # Oriya |
| 65 | + "si": "nplurals=2; plural=(n != 1);", # Sinhala |
| 66 | + "ne": "nplurals=2; plural=(n != 1);", # Nepali |
| 67 | + "mr": "nplurals=2; plural=(n != 1);", # Marathi |
| 68 | + "ur": "nplurals=2; plural=(n != 1);", # Urdu |
| 69 | + "az": "nplurals=2; plural=(n != 1);", # Azerbaijani |
| 70 | + "uz": "nplurals=2; plural=(n != 1);", # Uzbek |
| 71 | + "kk": "nplurals=2; plural=(n != 1);", # Kazakh |
| 72 | + "mn": "nplurals=2; plural=(n != 1);", # Mongolian |
| 73 | + "sq": "nplurals=2; plural=(n != 1);", # Albanian |
| 74 | + "eu": "nplurals=2; plural=(n != 1);", # Basque |
| 75 | + "ca": "nplurals=2; plural=(n != 1);", # Catalan |
| 76 | + "gl": "nplurals=2; plural=(n != 1);", # Galician |
| 77 | + "tr": "nplurals=2; plural=(n != 1);", # Turkish |
| 78 | + "af": "nplurals=2; plural=(n != 1);", # Afrikaans |
| 79 | + "fil": "nplurals=2; plural=(n != 1);", # Filipino |
| 80 | + # Languages with 2 plural forms: plural=(n > 1) |
| 81 | + "fr": "nplurals=2; plural=(n > 1);", # French |
| 82 | + "br": "nplurals=2; plural=(n > 1);", # Breton |
| 83 | + # Languages with 3 plural forms |
| 84 | + "pl": ( |
| 85 | + "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && " |
| 86 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 87 | + ), # Polish |
| 88 | + "ru": ( |
| 89 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && " |
| 90 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 91 | + ), # Russian |
| 92 | + "uk": ( |
| 93 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && " |
| 94 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 95 | + ), # Ukrainian |
| 96 | + "be": ( |
| 97 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && " |
| 98 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 99 | + ), # Belarusian |
| 100 | + "sr": ( |
| 101 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && " |
| 102 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 103 | + ), # Serbian |
| 104 | + "hr": ( |
| 105 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && " |
| 106 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 107 | + ), # Croatian |
| 108 | + "bs": ( |
| 109 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && " |
| 110 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 111 | + ), # Bosnian |
| 112 | + "cs": "nplurals=3; plural=(n==1 ? 0 : (n>=2 && n<=4) ? 1 : 2);", # Czech |
| 113 | + "sk": "nplurals=3; plural=(n==1 ? 0 : (n>=2 && n<=4) ? 1 : 2);", # Slovak |
| 114 | + "lt": ( |
| 115 | + "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " |
| 116 | + "(n%100<10 || n%100>=20) ? 1 : 2);" |
| 117 | + ), # Lithuanian |
| 118 | + "hy": "nplurals=3; plural=(n==1 ? 0 : n>=2 && n<=4 ? 1 : 2);", # Armenian |
| 119 | + "ro": ( |
| 120 | + "nplurals=3; plural=(n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);" |
| 121 | + ), # Romanian |
| 122 | + # Languages with 4 plural forms |
| 123 | + "cy": ( |
| 124 | + "nplurals=4; plural=(n==1 ? 0 : n==2 ? 1 : (n==8 || n==11) ? 2 : 3);" |
| 125 | + ), # Welsh |
| 126 | + "ga": "nplurals=4; plural=(n==1 ? 0 : n==2 ? 1 : (n>2 && n<7) ? 2 : 3);", # Irish |
| 127 | + "gd": ( |
| 128 | + "nplurals=4; plural=(n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : " |
| 129 | + "(n>2 && n<20) ? 2 : 3);" |
| 130 | + ), # Scottish Gaelic |
| 131 | + "mt": ( |
| 132 | + "nplurals=4; plural=(n==1 ? 0 : n==0 || (n%100>=2 && n%100<=10) ? 1 : " |
| 133 | + "(n%100>=11 && n%100<=19) ? 2 : 3);" |
| 134 | + ), # Maltese |
| 135 | + # Languages with 6 plural forms |
| 136 | + "ar": ( |
| 137 | + "nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && " |
| 138 | + "n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5);" |
| 139 | + ), # Arabic |
| 140 | + # Other languages |
| 141 | + "fa": "nplurals=2; plural=(n==0 || n==1 ? 0 : 1);", # Persian/Farsi |
| 142 | + "hu": "nplurals=2; plural=(n != 1);", # Hungarian |
| 143 | + "bg": "nplurals=2; plural=(n != 1);", # Bulgarian |
| 144 | + "am": "nplurals=2; plural=(n > 1);", # Amharic |
| 145 | +} |
| 146 | + |
| 147 | +# Default plural form fallback (English-style) |
| 148 | +# Used when a language code is not found in PLURAL_FORMS |
| 149 | +DEFAULT_PLURAL_FORM = "nplurals=2; plural=(n != 1);" |
| 150 | + |
| 151 | +# Typo patterns to fix in translation files |
| 152 | +TYPO_PATTERNS = [ |
| 153 | + ("Serch", "Search"), |
| 154 | +] |
| 155 | + |
| 156 | +# Backend PO file names |
| 157 | +BACKEND_PO_FILES = ["django.po", "djangojs.po"] |
| 158 | + |
| 159 | +# Backend plugin apps: (repo_dir, module_name) under translations/. |
| 160 | +# Used by sync_and_translate_language to sync/translate at |
| 161 | +# translations/<repo_dir>/<module_name>/conf/locale/<lang>/LC_MESSAGES/django.po. |
| 162 | +# When pulled in edx-platform (make pull_translations), these go to |
| 163 | +# conf/plugins-locale/plugins/<module_name>/. |
| 164 | +TRANSLATABLE_PLUGINS = [ |
| 165 | + ("open-edx-plugins", "ol_openedx_chat"), |
| 166 | +] |
| 167 | + |
| 168 | +# PO file header metadata |
| 169 | +PO_HEADER_PROJECT_VERSION = "0.1a" |
| 170 | +PO_HEADER_BUGS_EMAIL = "openedx-translation@googlegroups.com" |
| 171 | +PO_HEADER_POT_CREATION_DATE = "2023-06-13 08:00+0000" |
| 172 | +PO_HEADER_MIME_VERSION = "1.0" |
| 173 | +PO_HEADER_CONTENT_TYPE = "text/plain; charset=UTF-8" |
| 174 | +PO_HEADER_CONTENT_TRANSFER_ENCODING = "8bit" |
| 175 | +PO_HEADER_TRANSIFEX_TEAM_BASE_URL = "https://app.transifex.com/open-edx/teams/6205" |
| 176 | + |
| 177 | +# File and directory names |
| 178 | +TRANSLATION_FILE_NAMES = { |
| 179 | + "transifex_input": "transifex_input.json", |
| 180 | + "english": "en.json", |
| 181 | + "messages_dir": "messages", |
| 182 | + "i18n_dir": "i18n", |
| 183 | + "locale_dir": "locale", |
| 184 | + "lc_messages": "LC_MESSAGES", |
| 185 | + "conf_dir": "conf", |
| 186 | + "edx_platform": "edx-platform", |
| 187 | +} |
| 188 | + |
| 189 | +# JSON file formatting |
| 190 | +DEFAULT_JSON_INDENT = 2 |
| 191 | + |
| 192 | +# Language code to human-readable name mapping |
| 193 | +# Used in PO file headers for Language-Team field |
| 194 | +LANGUAGE_MAPPING = { |
| 195 | + "ar": "Arabic", |
| 196 | + "de": "German", |
| 197 | + "el": "Greek", |
| 198 | + "es": "Spanish", |
| 199 | + "fr": "French", |
| 200 | + "hi": "Hindi", |
| 201 | + "id": "Indonesian", |
| 202 | + "ja": "Japanese", |
| 203 | + "kr": "Korean", |
| 204 | + "pt": "Portuguese", |
| 205 | + "ru": "Russian", |
| 206 | + "sq": "Albanian", |
| 207 | + "tr": "Turkish", |
| 208 | + "zh": "Chinese", |
| 209 | +} |
| 210 | + |
| 211 | +# Maximum number of retries for failed translation batches |
| 212 | +MAX_RETRIES = 3 |
| 213 | + |
| 214 | +# Glossary parsing constants |
| 215 | +EXPECTED_GLOSSARY_PARTS = 2 # English term and translation separated by "->" |
| 216 | + |
| 217 | +# HTTP Status Codes |
| 218 | +HTTP_OK = 200 |
| 219 | +HTTP_CREATED = 201 |
| 220 | +HTTP_NOT_FOUND = 404 |
| 221 | +HTTP_TOO_MANY_REQUESTS = 429 |
| 222 | +HTTP_UNPROCESSABLE_ENTITY = 422 |
| 223 | + |
| 224 | +# Error message length limit |
| 225 | +MAX_ERROR_MESSAGE_LENGTH = 200 |
| 226 | + |
| 227 | +# Maximum length for strings in log messages (truncate with "...") |
| 228 | +MAX_LOG_STRING_LENGTH = 50 |
| 229 | +MAX_LOG_ICU_STRING_LENGTH = 100 |
| 230 | + |
| 231 | +# Plural category counts (GNU gettext nplurals) |
| 232 | +PLURAL_CATEGORIES_ARABIC = 6 # zero, one, two, few, many, other |
| 233 | +PLURAL_CATEGORIES_FOUR = 4 # one, two, few, other |
| 234 | +PLURAL_CATEGORIES_THREE = 3 # one, few, other |
| 235 | +PLURAL_CATEGORIES_TWO = 2 # one, other (most languages) |
0 commit comments