danhper / python-i18n

Easy to use i18n library for Python
https://pypi.python.org/pypi/python-i18n
MIT License
228 stars 45 forks source link

Some string are slow to translate #4

Open davidmir opened 8 years ago

davidmir commented 8 years ago

Some strings are slow to translate. Any reason for this to happen or it may be something wrong on my side?

Thanks

danhper commented 8 years ago

Hi, thanks for reporting :smile:

Would it be possible that the string is slow to translate the first time you are trying to translate it? The translations are loaded the first time they are required, which could explain why it is slow.

Loading everything when the app is launched seems way better (I can't remember why I chose not to), so if this seems to be your issue and you would like to send a PR, I am of course open.

If it is really an issue for you and you don't have time to send a PR, please let me know and I will see what I can do!

If this does not seem to be your issue, it would be really nice if you could come up with a minimal example to reproduce it.

Thanks!

hernan0216 commented 4 years ago

Hi, had a similar issue in my notifications system. We build a system using async tasks to render, we get the message given a key in user.en.yml for english translation, and user.es.ym for spanish, we realized that we had some missing keys in user.es.yml. Since we render both languages the tasks were getting slowly and more slowly each time. We fix it adding the missing keys to user.es.yml but was a mess to track the notifications delay.

    async def _call(self, event):
        """
        render_message has the responsibility to identify the key and build the correct message
        to add in the notification.
        """
        .....
        for local in locales:
            i18n.set('locale', local)
            raw_text[local] = i18n.t("{}.{}".format(observer, key)). //<- here in some key doesn't exists.
danhper commented 4 years ago

Hi, thanks for the update, and sorry for the trouble. I think this could easily be fixed by implementing a function to eagerly load the translations at boot time but I do not have time to add this right now. I would be very open to merging a PR for that, though. Thanks!