[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Translation: Extend translation extraction (getstrings) to support JavaScript and Vue files
"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a31b8763a793_38e29870934ca@gitlab-sidekiq-low-urgency-cpu-bound-v2-c9dcc9984-gv4k5.mail> |
ushindi bienvenu pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
c57b451b by Moïse Nturubika at 2026-06-16T20:37:51+00:00
[ENH] Translation: Extend translation extraction (getstrings) to support JavaScript and Vue files
---
* [REF] Convert JavaScript translation file extractor to a PSR-4 namespace
* [ENH] Translation: Extend translation extraction (getstrings) to support JavaScript and Vue files
See merge request tikiwiki/tiki!9924
- - - - -
2 changed files:
- lib/core/Tiki/Command/GetStringsCommand.php
- + lib/language/FileType/Js.php
Changes:
=====================================
lib/core/Tiki/Command/GetStringsCommand.php
=====================================
@@ -9,6 +9,7 @@ namespace Tiki\Command;
use Language_CollectFiles;
use Language_FileType_Php;
use Language_FileType_Tpl;
+use Tiki\Lib\Language\FileType\Js as Language_FileType_Js;
use Language_GetStrings;
use Language_WriteFile_Factory;
use Symfony\Component\Console\Attribute\AsCommand;
@@ -129,6 +130,7 @@ class GetStringsCommand extends Command
$getStrings->addFileType(new Language_FileType_Php());
$getStrings->addFileType(new Language_FileType_Tpl());
+ $getStrings->addFileType(new Language_FileType_Js());
// skip the following directories
$getStrings->collectFiles->setExcludeDirs($excludeDirs);
=====================================
lib/language/FileType/Js.php
=====================================
@@ -0,0 +1,68 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+namespace Tiki\Lib\Language\FileType;
+
+/**
+ * @package Tiki
+ * @subpackage Language
+ * Define properties to collect translatable
+ * strings from JavaScript and Vue files.
+ */
+class Js extends \Language_FileType
+{
+ protected $regexes = [
+ 'singleQuoted' => '|\Wtra?\s*\(\s*\'(.+?)\'\s*[\),]|s', // strings encapsulated with single quotes
+ 'doubleQuoted' => '|\Wtra?\s*\(\s*"(.+?)"\s*[\),]|s', // strings encapsulated with double quotes
+ 'backtickQuoted' => '|\Wtra?\s*\(\s*`(.+?)`\s*[\),]|s' // template literals (backticks)
+ ];
+
+ protected $extensions = ['.js', '.vue'];
+
+ protected $cleanupRegexes = [
+ "!/\*.*?\*/!s" => '', // Block comments
+ "!^\s*//.*$!m" => '', // Line comments
+ '/\Wtra?\s*\((["\'\`])\1\)/' => '', // remove empty calls to tra()
+ ];
+
+ /**
+ * Post process method for regex that collect single quoted strings.
+ *
+ * @param array $strings
+ * @return array
+ */
+ public function singleQuoted(array $strings): array
+ {
+ return str_replace("\'", "'", $strings);
+ }
+
+ /**
+ * Post process method for regex that collect double quoted strings.
+ *
+ * @param array $strings
+ * @return array
+ */
+ public function doubleQuoted(array $strings): array
+ {
+ foreach ($strings as $key => $string) {
+ $strings[$key] = \Language::removePhpSlashes($string);
+ }
+
+ return $strings;
+ }
+
+ /**
+ * Post process method for regex that collect backtick quoted strings.
+ *
+ * @param array $strings
+ * @return array
+ */
+ public function backtickQuoted(array $strings): array
+ {
+ return str_replace("\`", "`", $strings);
+ }
+}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/c57b451b144b46fc36bcb5fe99f25f0d29796466
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/c57b451b144b46fc36bcb5fe99f25f0d29796466
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs