Set up the GNUTranslations context with regard to output charset. This translation object will be constructed out of multiple GNUTranslations objects by merging their catalogs. It will construct an object for the requested language and add a fallback to the default language, if it'
| 128 | |
| 129 | |
| 130 | class DjangoTranslation(gettext_module.GNUTranslations): |
| 131 | """ |
| 132 | Set up the GNUTranslations context with regard to output charset. |
| 133 | |
| 134 | This translation object will be constructed out of multiple GNUTranslations |
| 135 | objects by merging their catalogs. It will construct an object for the |
| 136 | requested language and add a fallback to the default language, if it's |
| 137 | different from the requested language. |
| 138 | """ |
| 139 | |
| 140 | domain = "django" |
| 141 | |
| 142 | def __init__(self, language, domain=None, localedirs=None): |
| 143 | """Create a GNUTranslations() using many locale directories""" |
| 144 | gettext_module.GNUTranslations.__init__(self) |
| 145 | if domain is not None: |
| 146 | self.domain = domain |
| 147 | |
| 148 | self.__language = language |
| 149 | self.__to_language = to_language(language) |
| 150 | self.__locale = to_locale(language) |
| 151 | self._catalog = None |
| 152 | # If a language doesn't have a catalog, use the Germanic default for |
| 153 | # pluralization: anything except one is pluralized. |
| 154 | self.plural = lambda n: int(n != 1) |
| 155 | |
| 156 | if self.domain == "django": |
| 157 | if localedirs is not None: |
| 158 | # A module-level cache is used for caching 'django' |
| 159 | # translations |
| 160 | warnings.warn( |
| 161 | "localedirs is ignored when domain is 'django'.", RuntimeWarning |
| 162 | ) |
| 163 | localedirs = None |
| 164 | self._init_translation_catalog() |
| 165 | |
| 166 | if localedirs: |
| 167 | for localedir in localedirs: |
| 168 | translation = self._new_gnu_trans(localedir) |
| 169 | self.merge(translation) |
| 170 | else: |
| 171 | self._add_installed_apps_translations() |
| 172 | |
| 173 | self._add_local_translations() |
| 174 | if ( |
| 175 | self.__language == settings.LANGUAGE_CODE |
| 176 | and self.domain == "django" |
| 177 | and self._catalog is None |
| 178 | ): |
| 179 | # default lang should have at least one translation file available. |
| 180 | raise OSError( |
| 181 | "No translation files found for default language %s." |
| 182 | % settings.LANGUAGE_CODE |
| 183 | ) |
| 184 | self._add_fallback(localedirs) |
| 185 | if self._catalog is None: |
| 186 | # No catalogs found for this language, set an empty catalog. |
| 187 | self._catalog = TranslationCatalog() |
no outgoing calls
no test coverage detected