dashes not allowed in static references
Minimal non-working example:
pip install i18nice[YAML]
translation/a.en.yml:
en:
a-key: aValue
translation/b.en.yml:
en:
a-key: "%{a.a-key}"
static-ref.py:
import i18n
i18n.load_path.append("./translation")
print("b.a-key=", i18n.t("b.a-key"))
Produces
Traceback (most recent call last):
File "static_ref.py", line 8, in <module>
print("b.akey=", i18n.t("b.akey"))
.......
File "/i18n/formatters.py", line 57, in convert
self._invalid(mo)
File "/python3.12/string.py", line 101, in _invalid
raise ValueError('Invalid placeholder in string: line %d, col %d' %
ValueError: Invalid placeholder in string: line 1, col 1
It confused me for quite a while because I assumed it wouldn't find the needed key a.a-key.
This is most likely because this string formatting does not allow dashes.
I have not checked other symbols like underscore, whitespace of any kind, weird unicode, comma, semicolon, ...
Proposition: add a warning in the documentation which symbols are OK for the keys. Note that this is (only) important if you use static references.
unfortunately the official documentation is not that helpful: key Optional. Mapping key, consisting of a parenthesised sequence of characters (for example, (somename)).
from https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html
It's because of regular expressions formatters use. It's possible to add dash support.
That would of course also be nice (if it doesn't create other problems). I didn't notice this regular expression. Maybe add it to the docs so that users exactly know what's allowed?
Hello, sorry, I forgot about this issue 💀 Will fix tomorrow.