mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 02:16:09 -05:00
[i18n] Pass over economy, filter, general, image, mod
Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Callable, Union
|
||||
|
||||
from . import commands
|
||||
|
||||
@@ -113,9 +115,9 @@ def _normalize(string, remove_newline=False):
|
||||
ends_with_space = s[-1] in " \n\t\r"
|
||||
if remove_newline:
|
||||
newline_re = re.compile("[\r\n]+")
|
||||
s = " ".join(filter(bool, newline_re.split(s)))
|
||||
s = " ".join(filter(bool, s.split("\t")))
|
||||
s = " ".join(filter(bool, s.split(" ")))
|
||||
s = " ".join(filter(None, newline_re.split(s)))
|
||||
s = " ".join(filter(None, s.split("\t")))
|
||||
s = " ".join(filter(None, s.split(" ")))
|
||||
if starts_with_space:
|
||||
s = " " + s
|
||||
if ends_with_space:
|
||||
@@ -149,10 +151,10 @@ def get_locale_path(cog_folder: Path, extension: str) -> Path:
|
||||
return cog_folder / "locales" / "{}.{}".format(get_locale(), extension)
|
||||
|
||||
|
||||
class Translator:
|
||||
class Translator(Callable[[str], str]):
|
||||
"""Function to get translated strings at runtime."""
|
||||
|
||||
def __init__(self, name, file_location):
|
||||
def __init__(self, name: str, file_location: Union[str, Path, os.PathLike]):
|
||||
"""
|
||||
Initializes an internationalization object.
|
||||
|
||||
@@ -173,7 +175,7 @@ class Translator:
|
||||
|
||||
self.load_translations()
|
||||
|
||||
def __call__(self, untranslated: str):
|
||||
def __call__(self, untranslated: str) -> str:
|
||||
"""Translate the given string.
|
||||
|
||||
This will look for the string in the translator's :code:`.pot` file,
|
||||
|
||||
Reference in New Issue
Block a user