[IMP] *: unify sprintf and gettext

Improve gettext to directly handle value injection within translations,
removing the need for sprintf.

closes odoo/odoo#123932

Related: odoo/enterprise#45370
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
This commit is contained in:
Louis Wicket (wil)
2023-08-10 18:14:04 +02:00
parent 62fba62067
commit f1722c7334
123 changed files with 353 additions and 495 deletions
@@ -7,7 +7,6 @@ import dom from "@web/legacy/js/core/dom";
import Dialog from "@web/legacy/js/core/dialog";
import Widget from "@web/legacy/js/core/widget";
import localStorage from "@web/legacy/js/core/local_storage";
import { sprintf } from "@web/core/utils/strings";
import { debounce } from "@web/core/utils/timing";
import { sortBy } from "@web/core/utils/arrays";
import { pick } from "@web/core/utils/objects";
@@ -429,11 +428,11 @@ var ViewEditor = Widget.extend({
this.aceEditor.setSession(editingSession);
if (this.currentType === 'xml') {
this.$viewID.text(sprintf(_t("Template ID: %s"), this.views[resID].key));
this.$viewID.text(_t("Template ID: %s", this.views[resID].key));
} else if (this.currentType === 'scss') {
this.$viewID.text(sprintf(_t("SCSS file: %s"), resID));
this.$viewID.text(_t("SCSS file: %s", resID));
} else {
this.$viewID.text(sprintf(_t("JS file: %s"), resID));
this.$viewID.text(_t("JS file: %s", resID));
}
const isCustomized = this._isCustomResource(resID);
this.$lists[this.currentType].select2('val', resID);
@@ -10,7 +10,7 @@ import options from "@web_editor/js/editor/snippets.options";
import SmoothScrollOnDrag from "@web_editor/js/editor/smooth_scroll_on_drag";
import weUtils from "@web_editor/js/common/utils";
import * as gridUtils from "@web_editor/js/common/grid_layout_utils";
import { sprintf, escape } from "@web/core/utils/strings";
import { escape } from "@web/core/utils/strings";
const QWeb = core.qweb;
import { closestElement, isUnremovable } from "@web_editor/js/editor/odoo-editor/src/utils/utils";
import { debounce, throttleForAnimation } from "@web/core/utils/timing";
@@ -2958,12 +2958,12 @@ var SnippetsMenu = Widget.extend({
const btnRenameEl = document.createElement('we-button');
btnRenameEl.dataset.snippetId = $snippet.data('oeSnippetId');
btnRenameEl.classList.add('o_rename_btn', 'fa', 'fa-pencil', 'btn', 'o_we_hover_success');
btnRenameEl.title = sprintf(_t("Rename %s"), name);
btnRenameEl.title = _t("Rename %s", name);
$snippet.append(btnRenameEl);
const btnEl = document.createElement('we-button');
btnEl.dataset.snippetId = $snippet.data('oeSnippetId');
btnEl.classList.add('o_delete_btn', 'fa', 'fa-trash', 'btn', 'o_we_hover_danger');
btnEl.title = sprintf(_t("Delete %s"), name);
btnEl.title = _t("Delete %s", name);
$snippet.append(btnEl);
}
})
@@ -3830,9 +3830,9 @@ var SnippetsMenu = Widget.extend({
var moduleID = $snippet.data('moduleId');
var name = $snippet.attr('name');
new Dialog(this, {
title: sprintf(_t("Install %s"), name),
title: _t("Install %s", name),
size: 'medium',
$content: $('<div/>', {text: sprintf(_t("Do you want to install the %s App?"), name)}).append(
$content: $('<div/>', {text: _t("Do you want to install the %s App?", name)}).append(
$('<a/>', {
target: '_blank',
href: '/web#id=' + encodeURIComponent(moduleID) + '&view_type=form&model=ir.module.module&action=base.open_module_tree',
@@ -3858,7 +3858,7 @@ var SnippetsMenu = Widget.extend({
}).guardedCatch(reason => {
reason.event.preventDefault();
this.close();
const message = sprintf(Markup(_t("Could not install module <strong>%s</strong>")), name);
const message = Markup(_t("Could not install module <strong>%s</strong>", escape(name)));
self.displayNotification({
message: message,
type: 'danger',
@@ -3919,7 +3919,7 @@ var SnippetsMenu = Widget.extend({
new Dialog(this, {
size: 'medium',
title: _t('Confirmation'),
$content: $('<div><p>' + sprintf(_t("Are you sure you want to delete the snippet: %s?"), $snippet.attr('name')) + '</p></div>'),
$content: $('<div><p>' + _t("Are you sure you want to delete the snippet: %s?", $snippet.attr('name')) + '</p></div>'),
buttons: [{
text: _t("Yes"),
close: true,
@@ -35,7 +35,6 @@ import {
} from "@web_editor/js/editor/image_processing";
import * as OdooEditorLib from "@web_editor/js/editor/odoo-editor/src/OdooEditor";
import {SIZES, MEDIAS_BREAKPOINTS} from "@web/core/ui/ui_service";
import { sprintf } from "@web/core/utils/strings";
import { uniqueId } from "@web/core/utils/functions";
import { pick } from "@web/core/utils/objects";
import { _t } from "@web/core/l10n/translation";
@@ -5846,14 +5845,14 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
1024: ['1024px', 'image/webp'],
1920: ['1920px', 'image/webp'],
};
widths[img.naturalWidth] = [sprintf(_t("%spx"), img.naturalWidth), 'image/webp'];
widths[optimizedWidth] = [sprintf(_t("%spx (Suggested)"), optimizedWidth), 'image/webp'];
widths[img.naturalWidth] = [_t("%spx", img.naturalWidth), 'image/webp'];
widths[optimizedWidth] = [_t("%spx (Suggested)", optimizedWidth), 'image/webp'];
const imgMimetype = this._getImageMimetype(img);
widths[maxWidth] = [sprintf(_t("%spx (Original)"), maxWidth), imgMimetype];
widths[maxWidth] = [_t("%spx (Original)", maxWidth), imgMimetype];
if (imgMimetype !== 'image/webp') {
// Avoid a key collision by subtracting 0.1 - putting the webp
// above the original format one of the same size.
widths[maxWidth - 0.1] = [sprintf(_t("%spx"), maxWidth), 'image/webp'];
widths[maxWidth - 0.1] = [_t("%spx", maxWidth), 'image/webp'];
}
return Object.entries(widths)
.filter(([width]) => width <= maxWidth)
@@ -8047,7 +8046,7 @@ registry.SnippetSave = SnippetOptionWidget.extend({
reloadEditor: true,
invalidateSnippetCache: true,
onSuccess: async () => {
const defaultSnippetName = sprintf(_t("Custom %s"), this.data.snippetName);
const defaultSnippetName = _t("Custom %s", this.data.snippetName);
const targetCopyEl = this.$target[0].cloneNode(true);
delete targetCopyEl.dataset.name;
// By the time onSuccess is called after request_save, the