Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML arrays not supported #22

Open
ZRunner opened this issue Oct 20, 2020 · 0 comments
Open

YAML arrays not supported #22

ZRunner opened this issue Oct 20, 2020 · 0 comments

Comments

@ZRunner
Copy link

ZRunner commented Oct 20, 2020

Hello!
Either I didn't understand something, or it looks like that package doesn't support translations arrays.
I tried to put an array in my yaml file, which is correctly parsed and all, but it looks like trying to get it with i18n.t() raises a nice TypeError, when trying to format a string-which-is-actually-a-list.

Here's the YAML content I put :

fr:
  time:
    months:
      - janvier
      - février
      - mars
      - avril
      - mai
      - juin
      - juillet
      - août
      - septembre
      - octobre
      - novembre
      - décembre

And the error output:

Traceback (most recent call last):
  File "/Users/.../languages.py", line 32, in tr
    return i18n.t(key, locale=lang)
  File "/usr/local/lib/python3.8/site-packages/i18n/translator.py", line 28, in t
    return translate(key, locale=locale, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/i18n/translator.py", line 44, in translate
    return TranslationFormatter(translation).format(**kwargs)
  File "/usr/local/lib/python3.8/site-packages/i18n/translator.py", line 18, in format
    return self.safe_substitute(**kwargs)
  File "/usr/local/Cellar/[email protected]/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/string.py", line 147, in safe_substitute
    return self.pattern.sub(convert, self.template)
TypeError: expected string or bytes-like object

I guess detecting the variable type before trying to apply a substitution would be enough to fix it, but to be honest I didn't really look at the internal code, so I let you handle that part.
EDIT: Just created a PR for you, let me know if I did something wrong!

Python version: Python 3.8.6
Package version: 0.3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant