| 18 | |
| 19 | |
| 20 | def init( |
| 21 | locale_dir: str | None = None, languages: list[str] | None = None |
| 22 | ) -> None: |
| 23 | try: |
| 24 | locale.setlocale(locale.LC_ALL, "") |
| 25 | except locale.Error: |
| 26 | # This means that the user's environment is broken. Let's just continue |
| 27 | # with the default C locale. |
| 28 | sys.stderr.write( |
| 29 | "Error: Your locale settings are not supported by " |
| 30 | "the system. Using the fallback 'C' locale instead. " |
| 31 | "Please fix your locale settings.\n" |
| 32 | ) |
| 33 | |
| 34 | global translator |
| 35 | if locale_dir is None: |
| 36 | locale_dir = os.path.join(package_dir, "translations") |
| 37 | |
| 38 | translator = gettext.translation( |
| 39 | "bpython", locale_dir, languages, fallback=True |
| 40 | ) |