Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
381ef49
feat: clone in temp directory
hasnain2808 Oct 18, 2021
f0a95ac
wip: use clone to generate messages
hasnain2808 Oct 20, 2021
ddbdd3d
wip: get_messages from cloned frappe apps
hasnain2808 Oct 21, 2021
add7901
wip: get messages from clone
hasnain2808 Oct 21, 2021
3490f10
wip: get messages from clone
hasnain2808 Oct 21, 2021
47be5f2
feat: job based string extraction
hasnain2808 Nov 1, 2021
e748b96
fix: export options too
hasnain2808 Nov 2, 2021
eac4a94
chore: remove stray prints
hasnain2808 Nov 2, 2021
8bb793e
feat: extract strings using ast from dicts
hasnain2808 Nov 3, 2021
13ff96a
refactor: convert classnames to nouns
hasnain2808 Nov 8, 2021
6600a64
feat: release translation via api
hasnain2808 Nov 17, 2021
9c5c6f1
feat: download translations via rest
hasnain2808 Nov 22, 2021
ec799c4
feat: job managememt for releases
hasnain2808 Nov 24, 2021
af90068
chore: add back get_context
hasnain2808 Nov 25, 2021
948ad3a
feat: extract string & release translation weekly
hasnain2808 Nov 25, 2021
fcb410f
feat: use one column for report, doctype and page
hasnain2808 Nov 29, 2021
1b29cef
feat: translate weekly from google
hasnain2808 Nov 29, 2021
b5b2ae9
chore: linting and isort
hasnain2808 Nov 29, 2021
ba9326d
test: add tests and fixtures for processors
hasnain2808 Jan 11, 2022
d1ddb57
feat: workspace for translator
hasnain2808 Jan 12, 2022
c718450
fix: backward compatible positions
hasnain2808 Jan 12, 2022
05ce2e3
feat: ship extra position data
hasnain2808 Jan 12, 2022
97d1584
chore: linting
hasnain2808 Jan 12, 2022
2722c8d
fix: run ast parsers only when needed
hasnain2808 Mar 3, 2022
d35b384
refactor: simplify string extraction and release workflow
hasnain2808 Mar 4, 2022
db73448
minor: update workspace
hasnain2808 Mar 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
frappe
13 changes: 9 additions & 4 deletions translator/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def add_translations(translation_map, contributor_name, contributor_email, langu


@frappe.whitelist(allow_guest=True)
def get_strings_for_translation(language, start=0, page_length=100, search_text=''):
def get_strings_for_translation(language, start=0, page_length=100, search_text='', app_name='%'):
return frappe.db.sql("""
SELECT * FROM (
SELECT
Expand All @@ -59,16 +59,20 @@ def get_strings_for_translation(language, start=0, page_length=100, search_text=
AND translated.language = %(language)s
AND (translated.contribution_status='Verified' OR translated.translation_source != 'Community Contribution')
)
Inner join `tabSource Message Position` as smp
on (
source.name=smp.parent
)
WHERE
source.disabled != 1 && (source.message like %(search_text)s or translated.translated like %(search_text)s)
source.disabled != 1 && ((source.message like %(search_text)s or translated.translated like %(search_text)s) and smp.app like %(app_name)s)
ORDER BY
translated_by_google
) as res
GROUP BY res.id
ORDER BY res.translated, res.translated_by_google, res.creation
LIMIT %(page_length)s
OFFSET %(start)s
""", dict(language=language, search_text='%' + search_text + '%', page_length=cint(page_length), start=cint(start)), as_dict=1)
""", dict(language=language, search_text='%' + search_text + '%', page_length=cint(page_length), start=cint(start), app_name=app_name), as_dict=1 )

@frappe.whitelist(allow_guest=True)
def get_source_additional_info(source, language=''):
Expand All @@ -81,7 +85,8 @@ def get_source_additional_info(source, language=''):

data['positions'] = frappe.get_all('Source Message Position', filters={
'parent': source,
}, fields=['position as path', 'line_no', 'app', 'app_version'])
}, fields=['position as path', 'line_no', 'app',
'app_version', 'module', 'type', 'document_name'])

return data

Expand Down
18 changes: 10 additions & 8 deletions translator/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def _copy_translations(context, from_lang, to_lang):
finally:
frappe.destroy()

def translate_from_google():
for lang in frappe.db.sql_list("select name from tabLanguage"):
try:
translate_untranslated_from_google(lang)
except requests.exceptions.HTTPError:
print("skipping {0}".format(lang))
continue
finally:
frappe.db.commit()

@click.command('translate-untranslated-all')
@pass_context
Expand All @@ -91,14 +100,7 @@ def _translate_untranslated_all(context):
try:
frappe.init(site=site)
frappe.connect()
for lang in frappe.db.sql_list("select name from tabLanguage"):
try:
translate_untranslated_from_google(lang)
except requests.exceptions.HTTPError:
print("skipping {0}".format(lang))
continue
finally:
frappe.db.commit()
translate_from_google()
finally:
frappe.destroy()

Expand Down
10 changes: 4 additions & 6 deletions translator/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ def get_formatted_messages():
message_map[(message, context)].append(position_dict)
return message_map

def write_csv_for_all_languages():
def write_csv_for_all_languages(app, basepath):
langs = frappe.db.sql_list("select name from tabLanguage")
for lang in langs:
for app in get_apps_to_be_translated():
print("Writing for {0}-{1}".format(app, lang))
path = os.path.join(frappe.get_app_path(app, "translations", lang + ".csv"))
write_csv(app, lang, path)
print("Writing for {0}-{1}".format(app, lang))
path = os.path.join(basepath,lang + ".csv")
write_csv(app, lang, path)

def write_csv(app, lang, path):
translations = get_translations_for_export(app, lang)
Expand Down Expand Up @@ -294,7 +293,6 @@ def get_lang_name(lang):
"key": frappe.conf.google_api_key,
"target": "en"
})

languages = resp.json()['data']['languages']
for l in languages:
if l['language'] == lang:
Expand Down
106 changes: 5 additions & 101 deletions translator/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,10 @@
clear_cache = "translator.helpers.clear_cache"

fixtures = ["Custom Field"]

# website_context = {
# 'logo_image_url': '/assets/translator/img/erp-icon.svg',
# 'brand_html': 'ERPNext Translator',
# 'brand_name': 'ERPNext Translator',
# "top_bar_items": [
# {"label": "Hall of Fame", "url": "/hall-of-fame", "right": 1},
# {"label": "Help", "url": "/help", "right": 1}
# ],
# "favicon": "/assets/translator/img/favicon.ico",
# }

# Includes in <head>
# ------------------

# include js, css files in header of desk.html
# app_include_css = "/assets/translator/css/translator.css"
# app_include_js = "/assets/translator/js/translator.js"

# include js, css files in header of web template
web_include_css = [
"/assets/translator/css/custom.css",
]

# Home Pages
# ----------

# application home page (will override Website Settings)
# home_page = "login"

# website user home page (by Role)
# role_home_page = {
# "Role": "home_page"
# }

# Generators
# ----------

# automatically create page for each record of this doctype
# website_generators = ["Web Page"]

# Installation
# ------------

# before_install = "translator.install.before_install"
# after_install = "translator.install.after_install"

# Desk Notifications
# ------------------
# See frappe.core.notifications.get_notification_config

# notification_config = "translator.notifications.get_notification_config"

# Permissions
# -----------
# Permissions evaluated in scripted ways

# permission_query_conditions = {
# "Event": "frappe.desk.doctype.event.event.get_permission_query_conditions",
# }
#
# has_permission = {
# "Event": "frappe.desk.doctype.event.event.has_permission",
# }

# Document Events
# ---------------
# Hook on document methods and events

# doc_events = {
# "*": {
# "on_update": "method",
# "on_cancel": "method",
# "on_trash": "method"
# }
# }

doc_events = {
"User": {
Expand All @@ -98,33 +26,9 @@
# ---------------

scheduler_events = {
# "all": [
# "translator.tasks.all"
# ],
# "daily": [
# "translator.tasks.daily"
# ],
# "hourly": [
# "translator.data.write_csv_for_all_languages"
# ],
# "weekly": [
# "translator.helpers.weekly_updates"
# ]
# "monthly": [
# "translator.helpers.monthly_updates"
# ]
"Weekly Long": [
"translator.translator.doctype.translator_app.translator_app.extract_strings_weekly",
"translator.translator.doctype.translator_app.translator_app.create_release_weekly",
"translator.translator.doctype.translator_app.translator_app.translate_from_google",
]
}

# get_website_user_home_page = "translator.helpers.get_home_page"

# Testing
# -------

# before_tests = "translator.install.before_tests"

# Overriding Whitelisted Methods
# ------------------------------
#
# override_whitelisted_methods = {
# "frappe.desk.doctype.event.event.get_events": "translator.event.get_events"
# }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2021, Frappe Technologies and contributors
// For license information, please see license.txt

frappe.ui.form.on('Extract Strings Job', {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "hash",
"creation": "2021-11-01 20:23:47.185465",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"status",
"translator_app",
"translator_app_source",
"repository_owner",
"failure_log"
],
"fields": [
{
"allow_on_submit": 1,
"default": "Queued",
"fieldname": "status",
"fieldtype": "Select",
"hidden": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Status",
"no_copy": 1,
"options": "Queued\nValidating\nExtracting Strings\nCompleted\nFailed",
"read_only": 1
},
{
"fieldname": "translator_app",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Translator App",
"options": "Translator App"
},
{
"allow_on_submit": 1,
"default": "No Logs Found. Please check Background Jobs Log.",
"depends_on": "eval: doc.status == 'Failed'",
"fieldname": "failure_log",
"fieldtype": "Code",
"label": "Failure Log",
"no_copy": 1,
"read_only": 1
},
{
"fetch_from": "translator_app.repository_owner",
"fieldname": "repository_owner",
"fieldtype": "Data",
"label": "Repository Owner"
},
{
"fieldname": "translator_app_source",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Translator App Source",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-03-04 18:04:12.360684",
"modified_by": "Administrator",
"module": "Translator",
"name": "Extract Strings Job",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Loading