From 4e5a9887028dcf7391c2b98199c80f27c76ac670 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 17 Jun 2013 12:09:53 +0530 Subject: [PATCH] [build/translate] now translate will work on demand --- .gitignore | 5 ++--- webnotes/build.py | 2 +- webnotes/translate.py | 23 +++++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 563e4f4bab..13cf7f26cf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ *.py~ *.comp.js *.DS_Store -user_files -logs -defs.py +locale +.wnf-lang-status diff --git a/webnotes/build.py b/webnotes/build.py index 71956ae9ed..143adb7daa 100644 --- a/webnotes/build.py +++ b/webnotes/build.py @@ -61,7 +61,7 @@ def check_public(): make() def check_lang(): - from webnotes.tranlate import update_translations + from webnotes.translate import update_translations update_translations() class Bundle: diff --git a/webnotes/translate.py b/webnotes/translate.py index 4f39660ee6..0bf6a9fcb2 100644 --- a/webnotes/translate.py +++ b/webnotes/translate.py @@ -42,22 +42,22 @@ def translate(lang=None): if lang=="all" or lang==None: languages = get_all_languages() - print "Extracting messages..." + print "Extracting / updating translatable strings..." build_message_files() + print "Compiling messages in one file..." export_messages(lang, '_lang_tmp.csv') for lang in languages: if lang != "en": filename = 'app/translations/'+lang+'.csv' print "For " + lang + ":" - print "Compiling messages in one file..." print "Translating via Google Translate..." google_translate(lang, '_lang_tmp.csv', filename) print "Updating language files..." import_messages(lang, filename) - print "Deleting temp files..." + print "Deleting temp file..." os.remove('_lang_tmp.csv') def get_all_languages(): @@ -70,22 +70,33 @@ def update_translations(): """ langstatus = {} languages = get_all_languages() - if os.path.exists(".wnf-lang-status"): - with open(".erpnext-lang-status", "r") as langstatusfile: + message_updated = False + status_file_path = "app/.wnf-lang-status" + + if os.path.exists(status_file_path): + with open(status_file_path, "r") as langstatusfile: langstatus = eval(langstatusfile.read()) for lang in languages: filename = 'app/translations/'+lang+'.csv' if langstatus.get(lang, None)!=os.path.getmtime(filename): print "Setting up lang files for " + lang + "..." + if not message_updated: + print "Extracting / updating translatable strings..." + build_message_files() + message_updated = True + print "Writing translations..." import_messages(lang, filename) langstatus[lang] = os.path.getmtime(filename) - with open(".wnf-lang-status", "w") as langstatusfile: + with open(status_file_path, "w") as langstatusfile: langstatus = langstatusfile.write(str(langstatus)) def build_message_files(): """build from doctypes, pages, database and framework""" + if not webnotes.conn: + webnotes.connect() + build_for_pages('lib/core') build_for_pages('app')