-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] template_translation: export all qweb views in module
- Loading branch information
Showing
8 changed files
with
105 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2024 Therp BV <http://therp.nl>. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
import os | ||
|
||
from api_login import get_args, get_config, get_session | ||
from template_get import template_get_receive | ||
from template_list import template_list_receive | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def template_write(xmlid, template_content, language=None): | ||
"""Write template contents to export directory. | ||
Files will get a name according to the format: | ||
<module>.<name>.<language>.xml | ||
""" | ||
config = get_config() | ||
config_dict = config["template_export"] | ||
export_directory = config_dict["export_directory"] | ||
os.makedirs(export_directory, exist_ok=True) | ||
lang = language or "en_US" | ||
path = os.path.join(export_directory, "%s.%s.xml" % (xmlid, lang)) | ||
with open(path, mode="w") as xmlfile: # Overwrite any existing content. | ||
xmlfile.write(template_content) | ||
|
||
|
||
def template_get_all(args): | ||
"""Export all module texts in language to files in ~/tmp/ directory.""" | ||
config = get_config() | ||
cookies = get_session(args, config) | ||
received = template_list_receive(args, cookies=cookies) | ||
template_list = received["result"]["template_list"] | ||
for xmlid in template_list: | ||
# Get template content one by one and write to file. | ||
complete_xmlid = "%s.%s" % (args.module, xmlid) | ||
received = template_get_receive(args, xmlid=complete_xmlid, cookies=cookies) | ||
template_content = received["result"]["template_content"] | ||
if not template_content: | ||
_logger.debug("Did not find content for xmlid %s", complete_xmlid) | ||
continue | ||
template_write(complete_xmlid, template_content, language=args.language) | ||
|
||
|
||
if __name__ == "__main__": | ||
main_args = get_args() | ||
template_get_all(main_args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters