You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The normalize_locales function should be rewritten to accept the loader from the --loader parameter, which will be the loader path. It should import this loader into the module and perform normalizations based on this loader.
However, to do this to PyI18nBaseLoader you need to add another abstract method named dump which will be responsible for overwriting the files.
The dump method should overwrite files from the given parameter new: dict in this case there will be standardized translations, you should retype by keys (locale) and for the corresponding key overwrite the corresponding files, also note that the method should also support namespace
In this way, the normalization will be independent of what loader you use and will work for any custom loader ( as long as the dump method has been correctly written.
EDIT: Actually, you can get rid of most of the code from the normalize module, because sorting for default loaders can be taken care of at the YAML/JSON level of the serializer. For custom loaders writing it in dump method is required, so after the normalization task, locales will be sorted and properly dumped.
EDIT2: I haven't thought this through completely and there is one bigger problem with my solution, I want that for the two built-in loaders the loaders don't need to specify which one specifically is used, first I have to find out somehow which loader is used in the project, using the ast module is probably not the best way.
The text was updated successfully, but these errors were encountered:
After some thought I decided to keep it simple and handle -l parameter (--loader) to pyi18n-tasks instead of trying to make this part of the code bulletproof and unnecessarily more complex. For built-in loaders it won't be a problem, because all you need to do is to take the appropriate name from the class that the user provides and select the appropriate class, but custom loaders need to be imported dynamically.
The
normalize_locales
function should be rewritten to accept the loader from the--loader
parameter, which will be the loader path. It should import this loader into the module and perform normalizations based on this loader.However, to do this to
PyI18nBaseLoader
you need to add another abstract method nameddump
which will be responsible for overwriting the files.The
dump
method should overwrite files from the given parameternew: dict
in this case there will be standardized translations, you should retype by keys (locale) and for the corresponding key overwrite the corresponding files, also note that the method should also support namespaceThen in the
normalize
module replace this:with simply:
In this way, the normalization will be independent of what loader you use and will work for any custom loader ( as long as the
dump
method has been correctly written.EDIT: Actually, you can get rid of most of the code from the
normalize
module, because sorting for default loaders can be taken care of at the YAML/JSON level of the serializer. For custom loaders writing it indump
method is required, so after the normalization task, locales will be sorted and properly dumped.EDIT2: I haven't thought this through completely and there is one bigger problem with my solution, I want that for the two built-in loaders the loaders don't need to specify which one specifically is used, first I have to find out somehow which loader is used in the project, using the
ast
module is probably not the best way.The text was updated successfully, but these errors were encountered: