Skip to content

Commit

Permalink
fix: Translation related issues (#11932)
Browse files Browse the repository at this point in the history
Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
  • Loading branch information
szufisher and surajshetty3416 committed Feb 1, 2021
1 parent 19428f2 commit 2b01fb0
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 49 deletions.
1 change: 1 addition & 0 deletions frappe/custom/doctype/custom_script/custom_script.js
Expand Up @@ -33,6 +33,7 @@ frappe.ui.form.on('Custom Script', {
}
],
primary_action: ({ cdt }) => {
cdt = d.get_field('cdt').value;
frm.events.add_script_for_doctype(frm, cdt);
d.hide();
}
Expand Down
6 changes: 3 additions & 3 deletions frappe/desk/page/leaderboard/leaderboard.js
Expand Up @@ -145,7 +145,7 @@ class Leaderboard {
df: {
fieldtype: 'DateRange',
fieldname: 'selected_date_range',
placeholder: "Date Range",
placeholder: __("Date Range"),
default: [frappe.datetime.month_start(), frappe.datetime.now_date()],
input_class: 'input-sm',
reqd: 1,
Expand Down Expand Up @@ -193,7 +193,7 @@ class Leaderboard {

this.$search_box =
$(`<div class="leaderboard-search form-group col-md-3">
<input type="text" placeholder="Search" data-element="search" class="form-control leaderboard-search-input input-sm">
<input type="text" placeholder=${ __("Search") } data-element="search" class="form-control leaderboard-search-input input-sm">
</div>`);

$(this.parent).find(".page-form").append(this.$search_box);
Expand Down Expand Up @@ -292,7 +292,7 @@ class Leaderboard {
.map(i => frappe.model.unscrub(i));
const fields = ["rank", "name", this.options.selected_filter_item];
const filters = fields.map(filter => {
const col = frappe.model.unscrub(filter);
const col = __(frappe.model.unscrub(filter));
return (
`<div class="leaderboard-item list-item_content ellipsis text-muted list-item__content--flex-2
header-btn-base ${filter}
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/file_uploader/index.js
Expand Up @@ -63,7 +63,7 @@ export default class FileUploader {

make_dialog() {
this.dialog = new frappe.ui.Dialog({
title: 'Upload',
title: __('Upload'),
fields: [
{
fieldtype: 'HTML',
Expand Down
1 change: 1 addition & 0 deletions frappe/public/js/frappe/form/controls/html.js
Expand Up @@ -9,6 +9,7 @@ frappe.ui.form.ControlHTML = frappe.ui.form.Control.extend({
},
get_content: function() {
var content = this.df.options || "";
content = __(content);
try {
return frappe.render(content, this);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/form/form.js
Expand Up @@ -941,7 +941,7 @@ frappe.ui.form.Form = class FrappeForm {
}

add_web_link(path, label) {
label = label || "See on Website";
label = __(label) || __("See on Website");
this.web_link = this.sidebar.add_user_action(__(label),
function() {}).attr("href", path || this.doc.route).attr("target", "_blank");
}
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/form/multi_select_dialog.js
Expand Up @@ -42,7 +42,7 @@ frappe.ui.form.MultiSelectDialog = class MultiSelectDialog {
title: __("Select {0}", [(this.doctype == '[Select]') ? __("value") : __(doctype_plural)]),
fields: fields,
primary_action_label: this.primary_action_label || __("Get Items"),
secondary_action_label: __("Make {0}", [me.doctype]),
secondary_action_label: __("Make {0}", [__(me.doctype)]),
primary_action: function () {
let filters_data = me.get_custom_filters();
me.action(me.get_checked_values(), cur_dialog.get_values(), me.args, filters_data);
Expand Down Expand Up @@ -356,4 +356,4 @@ frappe.ui.form.MultiSelectDialog = class MultiSelectDialog {
}
});
}
};
};
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/form/success_action.js
Expand Up @@ -37,7 +37,7 @@ frappe.ui.form.SuccessAction = class SuccessAction {
setting.message;

const $buttons = this.get_actions().map(action => {
const $btn = $(`<button class="next-action"><span>${action.label}</span></button>`);
const $btn = $(`<button class="next-action"><span>${__(action.label)}</span></button>`);
$btn.click(() => action.action(this.form));
return $btn;
});
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/list/list_sidebar.html
Expand Up @@ -10,7 +10,7 @@
</ul>
<ul class="list-unstyled sidebar-menu standard-actions">
{% if frappe.model.can_get_report(doctype) %}
<li class="list-sidebar-label">Views</li>
<li class="list-sidebar-label">{{__('Views')}}</li>
<li class="divider visible-sm visible-xs"></li>
<li class="list-link">
<div class="btn-group">
Expand Down Expand Up @@ -73,7 +73,7 @@
</a>
<ul class="dropdown-menu list-stats-dropdown" role="menu">
<div class="dropdown-search">
<input type="text" placeholder="Search" data-element="search" class="form-control input-xs">
<input type="text" placeholder=${ __("Search") } data-element="search" class="form-control input-xs">
</div>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/list/list_sidebar_group_by.js
Expand Up @@ -23,7 +23,7 @@ frappe.views.ListGroupBy = class ListGroupBy {
fields: this.get_group_by_dropdown_fields()
});

d.set_primary_action("Save", ({ group_by_fields }) => {
d.set_primary_action(__("Save"), ({ group_by_fields }) => {
frappe.model.user_settings.save(this.doctype, 'group_by_fields', group_by_fields || null);
this.group_by_fields = group_by_fields ? ['assigned_to', 'owner', ...group_by_fields] : ['assigned_to', 'owner'];
this.render_group_by_items();
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/translate.js
Expand Up @@ -12,7 +12,7 @@ frappe._ = function(txt, replace, context = null) {

let translated_text = '';

let key = txt.replace(/\n/g, "");
let key = txt; // txt.replace(/\n/g, "");
if (context) {
translated_text = frappe._messages[`${key}:${context}`];
}
Expand Down
1 change: 1 addition & 0 deletions frappe/public/js/frappe/ui/alt_keyboard_shortcuts.js
Expand Up @@ -128,6 +128,7 @@ frappe.ui.keys.AltShortcutGroup = class AltShortcutGroup {
return !this.is_taken(letter) && is_valid_char;
});
if (!shortcut_letter) {
$text_el.attr('data-label', text_content);
return;
}
for (let key in this.shortcuts_dict) {
Expand Down
10 changes: 5 additions & 5 deletions frappe/public/js/frappe/ui/group_by/group_by.html
Expand Up @@ -9,14 +9,14 @@
<option
data-doctype="{{parent_doctype}}"
value="{{groupby_conditions[parent_doctype][val].fieldname}}">
{{ groupby_conditions[parent_doctype][val].label }}
({{ parent_doctype }})
{{ __(groupby_conditions[parent_doctype][val].label) }}
({{ __(parent_doctype) }})
</option>
{% } else { %}
<option
data-doctype="{{parent_doctype}}"
value="{{groupby_conditions[parent_doctype][val].fieldname}}">
{{ groupby_conditions[parent_doctype][val].label }}
value="{{ groupby_conditions[parent_doctype][val].fieldname }}">
{{ __(groupby_conditions[parent_doctype][val].label) }}
</option>
{% } %}
{% } %}
Expand All @@ -26,7 +26,7 @@
<div class="col-sm-2 form-group">
<select class="aggregate-function form-control">
{% for condition in aggregate_function_conditions %}
<option value="{{condition.name}}">{{ condition.label }}</option>
<option value="{{condition.name}}">{{ __(condition.label) }}</option>
{% endfor %}
</select>
</div>
Expand Down
10 changes: 5 additions & 5 deletions frappe/public/js/frappe/ui/group_by/group_by.js
Expand Up @@ -12,9 +12,9 @@ frappe.ui.GroupBy = class {
setup_group_by_area() {
this.make_group_by_button();
let sql_aggregate_function = [
{name:'count', label: 'Count'},
{name:'sum', label: 'Sum'},
{name:'avg', label:'Average'}
{name: 'count', label: __('Count')},
{name: 'sum', label: __('Sum')},
{name: 'avg', label: __('Average')}
];
this.groupby_edit_area = $(frappe.render_template("group_by", {
doctype: this.doctype,
Expand Down Expand Up @@ -64,9 +64,9 @@ frappe.ui.GroupBy = class {
if (frappe.model.is_numeric_field(field.fieldtype)) {
let option_text = doctype == this.doctype
? field.label
: `${field.label} (${doctype})`;
: `${__(field.label)} (${__(doctype)})`;
this.aggregate_on_html+= `<option data-doctype="${doctype}"
value="${field.fieldname}">${option_text}</option>`;
value="${field.fieldname}">${__(option_text)}</option>`;
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions frappe/public/js/frappe/ui/link_preview.js
Expand Up @@ -190,7 +190,7 @@ frappe.ui.LinkPreview = class {
let label = key;
content_html += `
<div class="preview-field">
<div class='small preview-label text-muted bold'>${label}</div>
<div class='small preview-label text-muted bold'>${__(label)}</div>
<div class="small preview-value">${value}</div>
</div>
`;
Expand All @@ -202,8 +202,8 @@ frappe.ui.LinkPreview = class {
<div class="preview-popover-header">${image_html}
<div class="preview-header">
<div class="preview-main">
<a class="preview-name bold" href=${this.href}>${preview_data.preview_title}</a>
<span class="text-muted small">${this.doctype} ${id_html}</span>
<a class="preview-name bold" href=${this.href}>${__(preview_data.preview_title)}</a>
<span class="text-muted small">${__(this.doctype)} ${id_html}</span>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/ui/notifications/notifications.js
Expand Up @@ -148,8 +148,8 @@ frappe.ui.Notifications = class Notifications {

add_open_document_html(name, value, doc_dt, target = false) {
let label = this.open_docs_config[name]
? this.open_docs_config[name].label
: name;
? __(this.open_docs_config[name].label)
: __(name);
let title = target ? `title="${__('Your Target')}"` : '';
let $list_item = !target
? $(`<li><a class="badge-hover" data-action="route_to_document_type" data-doctype="${name}" ${title}>
Expand Down
14 changes: 7 additions & 7 deletions frappe/public/js/frappe/ui/toolbar/search.js
Expand Up @@ -212,21 +212,21 @@ frappe.search.SearchDialog = Class.extend({
var $search_results = $(frappe.render_template("search")).addClass('hide');
var $sidebar = $search_results.find(".search-sidebar").empty();
var sidebar_item_html = '<li class="module-sidebar-item list-link" data-category="{0}">' +
'<a><span class="ellipsis">{0}</span><i class="octicon octicon-chevron-right"' +
'<a><span class="ellipsis">{1}</span><i class="octicon octicon-chevron-right"' +
'></a></li>';

this.modal_state = 0;
this.full_lists = { 'All Results': $('<div class="module-body results-summary"></div>') };
this.nav_lists = {};

result_sets.forEach(function(set) {
$sidebar.append($(__(sidebar_item_html, [set.title])));
$sidebar.append($(__(sidebar_item_html, [set.title, __(set.title)])));
me.add_section_to_summary(set.title, set.results);
me.full_lists[set.title] = me.render_full_list(set.title, set.results, set.fetch_type);
});

if(result_sets.length > 1) {
$sidebar.prepend($(__(sidebar_item_html, ["All Results"])));
$sidebar.prepend($(__(sidebar_item_html, ['All Results', __('All Results')])));
}

this.update($search_results.clone());
Expand All @@ -237,8 +237,8 @@ frappe.search.SearchDialog = Class.extend({
var me = this, max_length = 20;
var $results_list = $(' <div class="module-body"><div class="row module-section full-list '+
type+'-section">'+'<div class="col-sm-12 module-section-column">' +
'<div class="back-link"><a class="all-results-link small"> All Results</a></div>' +
'<div class="h4 section-head">'+type+'</div>' +
'<div class="back-link"><a class="all-results-link small">' + __("All Results") + '</a></div>' +
'<div class="h4 section-head">'+__(type)+'</div>' +
'<div class="section-body"></div></div></div></div>');

var $results_col = $results_list.find('.module-section-column');
Expand Down Expand Up @@ -273,7 +273,7 @@ frappe.search.SearchDialog = Class.extend({
this.full_lists['All Results'].append($('<div class="row module-section"></div>'));
}
var $results_col = $(`<div class="col-sm-${col_width} module-section-column" data-type="${type}">
<div class="h4 section-head">${type}</div>
<div class="h4 section-head">${ __(type) }</div>
<div class="section-body"></div>
</div>`);
results.slice(0, section_length).forEach(function(result) {
Expand Down Expand Up @@ -424,4 +424,4 @@ frappe.search.SearchDialog = Class.extend({
},
},

});
});
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/ui/toolbar/search_header.html
Expand Up @@ -7,6 +7,6 @@
</a>
<a type="button" class="btn btn-default btn-sm btn-modal-close" data-dismiss="modal" aria-hidden="true">
<i class="octicon octicon-x visible-xs" style="padding: 1px 0px;"></i>
<span class="hidden-xs">Close</span>
<span class="hidden-xs">{{ __("Close") }}</span>
</a>
</div>
</div>
18 changes: 9 additions & 9 deletions frappe/public/js/frappe/ui/toolbar/search_utils.js
Expand Up @@ -481,47 +481,47 @@ frappe.search.utils = {
});
var in_keyword = keywords.split(" in ")[0];
return [{
title: "Recents",
title: __("Recents"),
fetch_type: "Nav",
results: sort_uniques(this.get_recent_pages(keywords))
},
{
title: "Create a new ...",
title: __("Create a new ..."),
fetch_type: "Nav",
results: sort_uniques(this.get_creatables(keywords))
},
{
title: "Lists",
title: __("Lists"),
fetch_type: "Nav",
results: lists
},
{
title: "Reports",
title: __("Reports"),
fetch_type: "Nav",
results: sort_uniques(this.get_reports(keywords))
},
{
title: "Administration",
title: __("Administration"),
fetch_type: "Nav",
results: sort_uniques(this.get_pages(keywords))
},
{
title: "Workspace",
title: __("Workspace"),
fetch_type: "Nav",
results: sort_uniques(this.get_workspaces(keywords))
},
{
title: "Dashboard",
title: __("Dashboard"),
fetch_type: "Nav",
results: sort_uniques(this.get_dashboards(keywords))
},
{
title: "Setup",
title: __("Setup"),
fetch_type: "Nav",
results: setup
},
{
title: "Find '" + in_keyword + "' in ... ",
title: __("Find '{0}' in ...", [in_keyword]),
fetch_type: "Nav",
results: sort_uniques(this.get_search_in_list(keywords))
}];
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/widgets/onboarding_widget.js
Expand Up @@ -30,7 +30,7 @@ export default class OnboardingWidget extends Widget {

let $step = $(`<div class="onboarding-step ${status}">
<i class="fa ${icon_class}" aria-hidden="true" title="${status}"></i>
<span id="title">${step.title}</span>
<span id="title">${__(step.title)}</span>
</div>`);

step.$step = $step;
Expand Down Expand Up @@ -435,7 +435,7 @@ export default class OnboardingWidget extends Widget {
super.set_title(title);
if (this.subtitle) {
let subtitle = $(
`<div class="widget-subtitle">${this.subtitle}</div>`
`<div class="widget-subtitle">${__(this.subtitle)}</div>`
);
subtitle.appendTo(this.title_field);
}
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/widgets/shortcut_widget.js
Expand Up @@ -81,7 +81,7 @@ export default class ShortcutWidget extends Widget {
set_count(count) {
const get_label = () => {
if (this.format) {
return this.format.replace(/{}/g, count);
return __(this.format).replace(/{}/g, count);
}
return count;
};
Expand Down
6 changes: 5 additions & 1 deletion frappe/translate.py
Expand Up @@ -118,6 +118,8 @@ def get_dict(fortype, name=None):
messages += frappe.db.sql("select 'DocType:', name from tabDocType")
messages += frappe.db.sql("select 'Role:', name from tabRole")
messages += frappe.db.sql("select 'Module:', name from `tabModule Def`")
messages += frappe.db.sql("select '', format from `tabDesk Shortcut` where format is not null")
messages += frappe.db.sql("select '', title from `tabOnboarding Step`")

message_dict = make_dict_from_messages(messages, load_user_translation=False)
message_dict.update(get_dict_from_hooks(fortype, name))
Expand Down Expand Up @@ -336,7 +338,9 @@ def get_messages_from_doctype(name):
options = d.options.split('\n')
if not "icon" in options[0]:
messages.extend(options)

if d.fieldtype=='HTML' and d.options:
messages.append(d.options)

# translations of roles
for d in meta.get("permissions"):
if d.role:
Expand Down

0 comments on commit 2b01fb0

Please sign in to comment.