-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Allow lazy loading of translations in gettext. #79809
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
Comments
When working on i18n, I realized that msgfmt.py did not generate any hash table. One step further, I realized that the gettext.py would not have used it because it unconditionnaly loads the whole translation files and contains the following TODO message: TODO:
I have studied the code, and found that it should not be too complex to implement it in pure Python. I have posted a message on python-ideas about it and here are my conclusion: Features: API changes: gettext.bindtextdomain(domain, localedir=None) would become gettext.translation(domain, localedir=None, languages=None, class_=None, gettext.install(domain, localedir=None, codeset=None, names=None) would The new caching parameter could receive the following values: The keepopen parameter would be a boolean: Implementation: The proposed implementation would simply replace this dictionary with a
That should allow to implement the new feature with minimal refactoring But I also propose to change msgfmt.py to build the hashtable. IMHO, the function should lie in the standard library probably as a submodule of gettext to allow various Python projects (pybabel, django) to directly use it instead of developping their own ones. I will probably submit a PR in a while but it will will require some time to propose a full implementation with a correct test coverage. |
I am going to try to implement this, performance notesI created a small bench marking setup. (.mo with ~10000 unique entries, called for middle entry) I found that a C program was roughly 32x faster than its Python equivalent at retrieving that entry. I also tested the affect of hash tables on the C implementation, and found a 10% speed up. I thought it would have more of an effect, realistically Python will probably only have a 5% speed up. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: