mediagoblin-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] Apply formatting


From: Ben Sturmfels
Subject: Re: [PATCH 1/2] Apply formatting
Date: Tue, 05 Oct 2021 15:43:12 +1100
User-agent: mu4e 1.6.6; emacs 27.2

Hi jgart,

Thanks for these patches. I don't want to discourage you from
contributing, but reformatting and adding type hints is perhaps not the
best use of your time. That's because it doesn't have any meaningful
impact on our users, it makes the `git blame` output less useful, and
also takes my time to review.

Can I encourage you to take a look at the issues below?

https://todo.sr.ht/~mediagoblin/mediagoblin
https://issues.mediagoblin.org/report/1 (especially those with 0.13.0
milestone).

Very happy to discuss in IRC if you're unsure of what to work on.

Regards,
Ben

On Tue, 05 Oct 2021, jgart wrote:

> ---
>  mediagoblin/tools/translate.py | 58 ++++++++++++++++++----------------
>  1 file changed, 30 insertions(+), 28 deletions(-)
>
> diff --git a/mediagoblin/tools/translate.py b/mediagoblin/tools/translate.py
> index ae1d73cb..b8d517d2 100644
> --- a/mediagoblin/tools/translate.py
> +++ b/mediagoblin/tools/translate.py
> @@ -27,22 +27,23 @@ from mediagoblin import mg_globals
>  ###################
>  
>  AVAILABLE_LOCALES = None
> -TRANSLATIONS_PATH = pkg_resources.resource_filename(
> -    'mediagoblin', 'i18n')
> +TRANSLATIONS_PATH = pkg_resources.resource_filename("mediagoblin", "i18n")
>  
>  # Known RTL languages
>  KNOWN_RTL = {"ar", "fa", "he", "iw", "ur", "yi", "ji"}
>  
> +
>  def is_rtl(lang):
>      """Returns true when the local language is right to left"""
>      return lang in KNOWN_RTL
>  
> +
>  def set_available_locales():
>      """Set available locales for which we have translations"""
>      global AVAILABLE_LOCALES
> -    locales=['en', 'en_US'] # these are available without translations
> +    locales = ["en", "en_US"]  # these are available without translations
>      for locale in localedata.locale_identifiers():
> -        if gettext.find('mediagoblin', TRANSLATIONS_PATH, [locale]):
> +        if gettext.find("mediagoblin", TRANSLATIONS_PATH, [locale]):
>              locales.append(locale)
>      AVAILABLE_LOCALES = locales
>  
> @@ -51,28 +52,27 @@ class ReallyLazyProxy(LazyProxy):
>      """
>      Like LazyProxy, except that it doesn't cache the value ;)
>      """
> +
>      def __init__(self, func, *args, **kwargs):
>          super().__init__(func, *args, **kwargs)
> -        object.__setattr__(self, '_is_cache_enabled', False)
> +        object.__setattr__(self, "_is_cache_enabled", False)
>  
>      def __repr__(self):
>          return "<{} for {}({!r}, {!r})>".format(
> -            self.__class__.__name__,
> -            self._func,
> -            self._args,
> -            self._kwargs)
> +            self.__class__.__name__, self._func, self._args, self._kwargs
> +        )
>  
>  
>  def locale_to_lower_upper(locale):
>      """
>      Take a locale, regardless of style, and format it like "en_US"
>      """
> -    if '-' in locale:
> -        lang, country = locale.split('-', 1)
> -        return f'{lang.lower()}_{country.upper()}'
> -    elif '_' in locale:
> -        lang, country = locale.split('_', 1)
> -        return f'{lang.lower()}_{country.upper()}'
> +    if "-" in locale:
> +        lang, country = locale.split("-", 1)
> +        return f"{lang.lower()}_{country.upper()}"
> +    elif "_" in locale:
> +        lang, country = locale.split("_", 1)
> +        return f"{lang.lower()}_{country.upper()}"
>      else:
>          return locale.lower()
>  
> @@ -81,9 +81,9 @@ def locale_to_lower_lower(locale):
>      """
>      Take a locale, regardless of style, and format it like "en_us"
>      """
> -    if '_' in locale:
> -        lang, country = locale.split('_', 1)
> -        return f'{lang.lower()}-{country.lower()}'
> +    if "_" in locale:
> +        lang, country = locale.split("_", 1)
> +        return f"{lang.lower()}-{country.lower()}"
>      else:
>          return locale.lower()
>  
> @@ -92,27 +92,28 @@ def get_locale_from_request(request):
>      """
>      Return most appropriate language based on prefs/request request
>      """
> -    request_args = (request.args, request.form)[request.method=='POST']
> +    request_args = (request.args, request.form)[request.method == "POST"]
>  
> -    if 'lang' in request_args:
> +    if "lang" in request_args:
>          # User explicitely demanded a language, normalize lower_uppercase
> -        target_lang = locale_to_lower_upper(request_args['lang'])
> +        target_lang = locale_to_lower_upper(request_args["lang"])
>  
> -    elif 'target_lang' in request.session:
> +    elif "target_lang" in request.session:
>          # TODO: Uh, ohh, this is never ever set anywhere?
> -        target_lang = request.session['target_lang']
> +        target_lang = request.session["target_lang"]
>      else:
>          # Pull the most acceptable language based on browser preferences
>          # This returns one of AVAILABLE_LOCALES which is aready 
> case-normalized.
>          # Note: in our tests request.accept_languages is None, so we need
>          # to explicitely fallback to en here.
> -        target_lang = request.accept_languages.best_match(AVAILABLE_LOCALES) 
> \
> -                      or "en_US"
> +        target_lang = request.accept_languages.best_match(AVAILABLE_LOCALES) 
> or "en_US"
>  
>      return target_lang
>  
> +
>  SETUP_GETTEXTS = {}
>  
> +
>  def get_gettext_translation(locale):
>      """
>      Return the gettext instance based on this locale
> @@ -127,7 +128,8 @@ def get_gettext_translation(locale):
>          this_gettext = SETUP_GETTEXTS[locale]
>      else:
>          this_gettext = gettext.translation(
> -            'mediagoblin', TRANSLATIONS_PATH, [locale], fallback=True)
> +            "mediagoblin", TRANSLATIONS_PATH, [locale], fallback=True
> +        )
>          if localedata.exists(locale):
>              SETUP_GETTEXTS[locale] = this_gettext
>      return this_gettext
> @@ -179,8 +181,7 @@ def pass_to_ngettext(*args, **kwargs):
>      The reason we can't have a global ngettext method is because
>      mg_globals gets swapped out by the application per-request.
>      """
> -    return mg_globals.thread_scope.translations.ngettext(
> -        *args, **kwargs)
> +    return mg_globals.thread_scope.translations.ngettext(*args, **kwargs)
>  
>  
>  def lazy_pass_to_ngettext(*args, **kwargs):
> @@ -193,6 +194,7 @@ def lazy_pass_to_ngettext(*args, **kwargs):
>      """
>      return ReallyLazyProxy(pass_to_ngettext, *args, **kwargs)
>  
> +
>  def lazy_pass_to_ungettext(*args, **kwargs):
>      """
>      Lazily pass to ungettext.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]