Skip to content

Commit

Permalink
Revert ".mo files created when they are not present"
Browse files Browse the repository at this point in the history
This reverts commit c05325a.
  • Loading branch information
casperlamboo committed Jan 3, 2024
1 parent 492b516 commit 76d1464
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
31 changes: 5 additions & 26 deletions UM/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Uranium is released under the terms of the LGPLv3 or higher.

import gettext
import polib
import os
import struct # Catching errors generated by gettext.
from typing import Any, Dict, Optional, cast, TYPE_CHECKING

Expand Down Expand Up @@ -203,17 +201,6 @@ def _replaceTags(self, string: str) -> str:

return output

def compile_po_to_mo(self, po_file_path, mo_file_path):
# Load the .po file
po = polib.pofile(po_file_path)

# Create or ensure the directory for the .mo file exists
mo_dir = os.path.dirname(mo_file_path)
os.makedirs(mo_dir, exist_ok=True)

# Compile the .po file to .mo
po.save_as_mofile(mo_file_path)

def _update(self) -> None:
"""Fill the catalogue by loading the translated texts from file (again)."""

Expand All @@ -228,19 +215,11 @@ def _update(self) -> None:

# Ask gettext for all the translations in the .mo files.
for path in Resources.getAllPathsForType(Resources.i18n):
name = cast(str, self.__name)
pofile = os.path.join(path, self.__language, '%s.po' % name)
if os.path.exists(pofile):
mofile = os.path.join(path, self.__language, 'LC_MESSAGES', '%s.mo' % name)
if not os.path.exists(mofile):
# create mo file
self.compile_po_to_mo(pofile, mofile)

if gettext.find(name, path, languages = [self.__language]):
try:
self.__translation = gettext.translation(cast(str, self.__name), path, languages = [self.__language])
except (EnvironmentError, struct.error, UnicodeDecodeError):
Logger.warning("Corrupt or inaccessible translation file: {fname}".format(fname = self.__name))
if gettext.find(cast(str, self.__name), path, languages = [self.__language]):
try:
self.__translation = gettext.translation(cast(str, self.__name), path, languages = [self.__language])
except (EnvironmentError, struct.error, UnicodeDecodeError):
Logger.warning("Corrupt or inaccessible translation file: {fname}".format(fname = self.__name))

self.__require_update = False

Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,3 @@ typing-extensions==4.3.0 \
colorama==0.4.5; \
sys_platform=="win32" \
--hash=sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da
polib==1.1.1; \
--hash=sha256:d3ee85e0c6788f789353416b1612c6c92d75fe6ccfac0029711974d6abd0f86d

0 comments on commit 76d1464

Please sign in to comment.