[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX] Interactive translation: Ensure placeholder variables (\%0, \%1, etc.) are...
"luci \(@luciash\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6913382b55102_2ce2be41577f@gitlab-sidekiq-low-urgency-cpu-bound-v2-5f7d69c697-nf5l8.mail> |
luci pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki
Commits:
ca226bec by Landry Bitege at 2025-11-11T13:13:02+00:00
[BP][FIX] Interactive translation: Ensure placeholder variables (\%0, \%1, etc.) are...
---
* [FIX] Interactive translation: Ensure placeholder variables (%0, %1, etc.) are preserved in suggested translations during interactive translation
---
* [FIX] Interactive translation: Ensure placeholder variables (%0, %1, etc.) are preserved in suggested translations during interactive translation
See merge request tikiwiki/tiki!8882
See merge request tikiwiki/tiki!8995
- - - - -
2 changed files:
- lib/language/LanguageTranslator.php
- lib/language/js/interactive_translation.js
Changes:
=====================================
lib/language/LanguageTranslator.php
=====================================
@@ -65,7 +65,7 @@ class LanguageTranslator
list($content, $out, $wasTranslated) = $this->traImpl($content, $this->lang, $args);
$out = typography($out, $this->lang, true);
- $this->populateCollectedTranslations($content, $out, $wasTranslated);
+ $this->populateCollectedTranslations($content, $out, $wasTranslated, $args);
return $out;
}
@@ -237,10 +237,10 @@ class LanguageTranslator
* @param $printed
* @param $isTranslated
*/
- private function populateCollectedTranslations($original, $printed, $isTranslated)
+ private function populateCollectedTranslations($original, $printed, $isTranslated, $args = [])
{
if (self::inInteractiveMode()) {
- $this->interactiveCollectedStrings[md5($original . '___' . $printed)] = [$original, html_entity_decode($printed), $isTranslated];
+ $this->interactiveCollectedStrings[md5($original . '___' . $printed)] = [$original, html_entity_decode($printed), $isTranslated, $args];
}
}
=====================================
lib/language/js/interactive_translation.js
=====================================
@@ -122,9 +122,9 @@ $(document).find('.container *').on("click", function( e ) {
if (this[2]) { // new ones in italic
r.find('td.original').css("font-style", 'italic');
}
- r.find(':hidden').val( this[0] );
- r.find(':text').val( this[1] );
- r.find('textarea').val(this[1]);
+ r.find(':hidden').val(this[0]);
+ r.find(':text').val(this[1]);
+ r.find('textarea').val(reverseArgReplace(this[1], this[3]));
return r[0];
} ) );
} else {
@@ -158,3 +158,67 @@ $(document).find('.container *').on("click", function( e ) {
$(this).css({"box-shadow":"", "-moz-box-shadow":"", "-webkit-box-shadow":""});
interTransDeepestElement = -1;
});
+
+/**
+ * Replace argument values in the content with their placeholders.
+ *
+ * @param {string} content Text with argument values
+ * @param {string[]} args Array of argument values
+ * @returns {string} Text with arguments replaced by their placeholders
+ */
+function reverseArgReplace(content, args) {
+ if (!args || args.length === 0 || !content) return content;
+
+ const matches = [];
+
+ args.forEach((val, i) => {
+ if (!val) return;
+ let offset = 0;
+ while (true) {
+ const pos = content.indexOf(val, offset);
+ if (pos === -1) break;
+ matches.push({
+ start: pos,
+ length: val.length,
+ arg: i
+ });
+ offset = pos + 1;
+ }
+ });
+
+ if (matches.length === 0) return content;
+
+ matches.sort((a, b) => b.length - a.length || a.start - b.start);
+
+ const selected = [];
+ matches.forEach(m => {
+ const s = m.start;
+ const e = s + m.length;
+ let overlap = selected.some(sel => !(e <= sel.start || s >= sel.start + sel.length));
+ if (!overlap) selected.push(m);
+ });
+
+ if (selected.length === 0) return content;
+
+ selected.sort((a, b) => a.start - b.start);
+ let out = '';
+ let cursor = 0;
+ selected.forEach(m => {
+ const start = m.start;
+ const len = m.length;
+ const argIndex = m.arg;
+
+ if (cursor < start) {
+ out += content.slice(cursor, start);
+ }
+
+ out += `%${argIndex}`;
+ cursor = start + len;
+ });
+
+ if (cursor < content.length) {
+ out += content.slice(cursor);
+ }
+
+ return out;
+}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ca226bec6da4ea3001b5d46211108a10db4b53e1
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ca226bec6da4ea3001b5d46211108a10db4b53e1
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs