@@ -89,7 +89,10 @@ def _build_cp1258_transliteration_rules() -> dict[str, str]:
8989]
9090
9191
92- def get_enc (lang_path : str = "" , file_path : str = "" ):
92+ _UTF_NAME_RE = re .compile (r".*_ee\.tra$" )
93+
94+
95+ def get_enc (lang_path : str = "" , file_path : str = "" ) -> str :
9396 """
9497 Infers encoding based on dir/PO name and file path.
9598 lang_path can be PO path or translation path, only basename is used.
@@ -124,8 +127,7 @@ def get_enc(lang_path: str = "", file_path: str = ""):
124127 if filename in UTF_FILENAMES :
125128 encoding = "utf-8"
126129
127- utf_name = re .compile (r".*_ee\.tra$" )
128- if utf_name .match (filename ):
130+ if _UTF_NAME_RE .match (filename ):
129131 encoding = "utf-8"
130132
131133 return encoding
@@ -164,9 +166,11 @@ def encode_custom(text: str, encoding: str = "utf-8") -> str:
164166 Encodes and decodes the given text using the specified encoding,
165167 replacing invalid characters.
166168 If encoding is 'cp1258', it uses the encode_vietnamese function.
169+ UTF-8 is a passthrough since all Python strings are valid UTF-8.
167170 """
171+ if encoding == "utf-8" :
172+ return text
168173 if encoding == "cp1258" :
169174 return encode_vietnamese (text )
170- else :
171- # Graceful fallback for replace, can't really protect against invalid characters being entered in Weblate?
172- return text .encode (encoding , "replace" ).decode (encoding )
175+ # Graceful fallback for replace, can't really protect against invalid characters being entered in Weblate?
176+ return text .encode (encoding , "replace" ).decode (encoding )
0 commit comments