On 17/09/18 09:53, Niki Spahiev wrote:

Is it possible to use f-strings when making multilingual software?
When i write non-hobby software translation is hard requirement.


At this moment, it seems that this is not possible.

My use case is not very unique and that's why I wrote the proposal in the first place. I'm working on a web server / application server. On the web, you have to take the users preferences into account, including language. If a user has the navigator configured for English, I have to return English (if I am doing i18n).

That's why I would like to see a parameter that can be passed to the f-string.

I don't think this should be too problematic, really.

pygettext.py extracts strings surrounded by _('') My proposal would be to do that with f-strings. Let pygettext.py extract f-strings.

The compiler can then rewrite these to normal unicode strings. For instance: f'Hi {user}'.language('es') would become T(_('Hi {user}'), 'es', user=user)

My first email had pseudo-code. This is my working function.

def T(translatable_string, language=None, *args, **kwargs):
    if args:
        print(args)

    if 'es' == language:
        # Return translated, formatted string return 
es.gettext(translatable_string).format(**kwargs)

    # Default, return formatted string return 
translatable_string.format(**kwargs)

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to