HOR-4915
This commit is contained in:
210
app/Console/Commands/PMTranslationsPlugins.php
Normal file
210
app/Console/Commands/PMTranslationsPlugins.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use G;
|
||||
use i18n_PO;
|
||||
use Illuminate\Console\Command;
|
||||
use ProcessMaker\Util\Translation\I18Next;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class PMTranslationsPlugins
|
||||
* @package ProcessMaker\Console\Commands
|
||||
*/
|
||||
class PMTranslationsPlugins extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'translation:plugin
|
||||
{--a|all : Translate all plugins}
|
||||
{--name=* : Input Plugin name}
|
||||
{--type=po : Input translation source(po|laravel)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Translation plugin of Processmaker';
|
||||
|
||||
/**
|
||||
* Path for plugins
|
||||
* @var string
|
||||
*/
|
||||
protected $pluginsPath;
|
||||
|
||||
/**
|
||||
* Class I18next
|
||||
* @var I18next
|
||||
*/
|
||||
protected $i18next;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->pluginsPath = realpath(base_path() . DIRECTORY_SEPARATOR . "workflow" . DIRECTORY_SEPARATOR . "engine" . DIRECTORY_SEPARATOR . "plugins");
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$pluginNames = $this->option('name');
|
||||
$processAll = $this->option('all');
|
||||
$processType = $this->option('type');
|
||||
$directoryPlugins = [];
|
||||
if ($processAll) {
|
||||
$directoryPlugins = $this->filterFiles(array_diff(scandir($this->pluginsPath), ['..', '.'])) ?: [];
|
||||
} elseif ($pluginNames) {
|
||||
$directoryPlugins = $pluginNames;
|
||||
} else {
|
||||
$this->comment("Please use the --all option or introduce the plugin name (--name=namePlugin)");
|
||||
return;
|
||||
}
|
||||
$this->info('Start converting');
|
||||
$bar = $this->output->createProgressBar(count($directoryPlugins));
|
||||
foreach ($directoryPlugins as $name) {
|
||||
if ($processType == 'po') {
|
||||
$this->generateI18nFromPoFiles($name);
|
||||
} elseif ($processType == 'laravel') {
|
||||
$this->generateI18nFromLaravelLang($name);
|
||||
}
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
$this->info("\nFinish");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate files i18n from .po.
|
||||
*
|
||||
* @param object $pluginName
|
||||
* @return void
|
||||
*/
|
||||
private function generateI18nFromPoFiles($pluginName)
|
||||
{
|
||||
$pluginPath = $this->pluginsPath . DIRECTORY_SEPARATOR . $pluginName;
|
||||
if (is_dir($pluginPath)) {
|
||||
// Translate for files .po in plugin
|
||||
$translationsDirectory = $pluginPath . DIRECTORY_SEPARATOR . 'translations';
|
||||
$scannedDirectory = is_dir($translationsDirectory) ? array_diff(scandir($translationsDirectory), ['..', '.']) : null;
|
||||
if ($scannedDirectory) {
|
||||
$this->i18next = new I18Next();
|
||||
foreach ($scannedDirectory as $index => $item) {
|
||||
$filePath = $translationsDirectory . DIRECTORY_SEPARATOR . $item;
|
||||
$pathParts = pathinfo($filePath);
|
||||
$isPofile = !empty($pathParts['extension']) && $pathParts['extension'] === 'po';
|
||||
|
||||
if ($isPofile) {
|
||||
$basename = explode('.', $pathParts['basename']);
|
||||
$language = $basename[1];
|
||||
|
||||
$this->i18next->setLanguage($language);
|
||||
|
||||
//read file .po
|
||||
$str = new stdClass();
|
||||
$poFile = new i18n_PO($filePath);
|
||||
$poFile->readInit();
|
||||
while ($translation = $poFile->getTranslation()) {
|
||||
$translatorComments = $poFile->translatorComments;
|
||||
$references = $poFile->references;
|
||||
|
||||
$ifContinue = empty($translatorComments[0]) && empty($translatorComments[1]) && empty($references[0]);
|
||||
if ($ifContinue) {
|
||||
continue;
|
||||
}
|
||||
$ifNotTranslation = !($translatorComments[0] === 'TRANSLATION');
|
||||
if ($ifNotTranslation) {
|
||||
continue;
|
||||
}
|
||||
$key = explode("/", $translatorComments[1]);
|
||||
$str->{$key[1]} = $translation['msgstr'];
|
||||
}
|
||||
$this->i18next->setPlugin($language, $pluginName, $str);
|
||||
}
|
||||
}
|
||||
$this->saveFileJs($pluginName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate files i18n from resource/lang/*.
|
||||
*
|
||||
* @param $pluginName
|
||||
* @return void
|
||||
*/
|
||||
private function generateI18nFromLaravelLang($pluginName)
|
||||
{
|
||||
$pluginPath = $this->pluginsPath . DIRECTORY_SEPARATOR . $pluginName;
|
||||
if (is_dir($pluginPath)) {
|
||||
// Translate for files resources/lang in plugin
|
||||
$translationsDirectory = $pluginPath . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'lang';
|
||||
$scannedDirectory = is_dir($translationsDirectory) ? array_diff(scandir($translationsDirectory), ['..', '.']) : null;
|
||||
if ($scannedDirectory) {
|
||||
$this->i18next = new I18Next();
|
||||
foreach ($scannedDirectory as $lang) {
|
||||
$dirLanguage = $pluginPath . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $lang;
|
||||
$scannedLanguage = is_dir($dirLanguage) ? array_diff(scandir($dirLanguage), ['..', '.']) : [];
|
||||
foreach ($scannedLanguage as $index => $item) {
|
||||
$filePath = $dirLanguage . DIRECTORY_SEPARATOR . $item;
|
||||
$pathParts = pathinfo($filePath);
|
||||
$isPhpFile = !empty($pathParts['extension']) && $pathParts['extension'] === 'php';
|
||||
if ($isPhpFile) {
|
||||
$file = explode(".", $item);
|
||||
array_pop($file);
|
||||
$filename = implode("_", $file);
|
||||
$arrayLanguage = [$filename => require_once($dirLanguage . DIRECTORY_SEPARATOR . $item)];
|
||||
$this->i18next->setLanguage($lang);
|
||||
$this->i18next->setPlugin($lang, $pluginName, json_decode(json_encode($arrayLanguage)));
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->saveFileJs($pluginName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save js file generate of translate files.
|
||||
*
|
||||
* @param string $pluginName
|
||||
*/
|
||||
private function saveFileJs($pluginName)
|
||||
{
|
||||
$folderToSave = $this->pluginsPath . DIRECTORY_SEPARATOR . $pluginName . DIRECTORY_SEPARATOR . "public_html" . DIRECTORY_SEPARATOR . "js";
|
||||
if (!is_dir($folderToSave)) {
|
||||
$create = $this->choice('The "js" folder does not exist, Do you want to create the folder?', ['Yes', 'No'], 0);
|
||||
if (strtolower($create) == 'yes') {
|
||||
G::mk_dir($folderToSave, 0775);
|
||||
}
|
||||
}
|
||||
$this->i18next->saveJs($pluginName, $folderToSave . DIRECTORY_SEPARATOR . $pluginName . ".i18n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove files, return only folders.
|
||||
*
|
||||
* @param $scannedDirectory
|
||||
* @return array
|
||||
*/
|
||||
private function filterFiles($scannedDirectory)
|
||||
{
|
||||
$onlyFolders = [];
|
||||
foreach ($scannedDirectory as $index => $item) {
|
||||
$pluginPath = $this->pluginsPath . DIRECTORY_SEPARATOR . $item;
|
||||
if (is_dir($pluginPath)) {
|
||||
array_push($onlyFolders, $item);
|
||||
}
|
||||
}
|
||||
return $onlyFolders;
|
||||
}
|
||||
}
|
||||
39
app/Console/Kernel.php
Normal file
39
app/Console/Kernel.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
Commands\PMTranslationsPlugins::class
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Closure based commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ use Illuminate\Contracts\Console\Kernel as Kernel2;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Contracts\Http\Kernel as Kernel4;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Console\Kernel;
|
||||
use Illuminate\Foundation\Exceptions\Handler;
|
||||
use Illuminate\Foundation\Http\Kernel as Kernel3;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
@@ -43,7 +42,7 @@ $app->singleton(
|
||||
|
||||
$app->singleton(
|
||||
Kernel2::class,
|
||||
Kernel::class
|
||||
App\Console\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"colosa/pmdynaform": "release/3.2.4-dev",
|
||||
"google/apiclient": "1.1.6",
|
||||
"dapphp/securimage": "^3.6",
|
||||
"psr/log":"1.0.0",
|
||||
"psr/log": "1.0.0",
|
||||
"monolog/monolog": "1.19.0",
|
||||
"geshi/geshi": "dev-master",
|
||||
"libchart/libchart": "1.4.0",
|
||||
@@ -46,8 +46,8 @@
|
||||
"TYPO3/class-alias-loader": "^1.0",
|
||||
"ralouphie/getallheaders": "^2.0",
|
||||
"smarty/smarty": "2.6.30",
|
||||
"pdepend/pdepend" : "@stable",
|
||||
"chumper/zipper" : "^1.0"
|
||||
"pdepend/pdepend": "@stable",
|
||||
"chumper/zipper": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fzaninotto/faker": "^1.7",
|
||||
@@ -64,8 +64,9 @@
|
||||
"ProcessMaker\\": "workflow/engine/src"
|
||||
},
|
||||
"psr-4": {
|
||||
"Maveriks\\": "framework/src/Maveriks/",
|
||||
"Tests\\": "tests/"
|
||||
"App\\": "app/",
|
||||
"Maveriks\\": "framework/src/Maveriks/",
|
||||
"Tests\\": "tests/"
|
||||
},
|
||||
"classmap": [
|
||||
"gulliver/system/",
|
||||
@@ -97,7 +98,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wimg/php-compatibility",
|
||||
"post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wimg/php-compatibility"
|
||||
"post-update-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wimg/php-compatibility"
|
||||
},
|
||||
"extra": {
|
||||
"typo3/class-alias-loader": {
|
||||
|
||||
2
gulliver/js/i18next/i18next.min.js
vendored
Normal file
2
gulliver/js/i18next/i18next.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,43 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* class.dbtable.php
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* i18n_PO
|
||||
* This class build biggers PO files without size limit and this not use much memory that the allowed
|
||||
*
|
||||
* @package gulliver.system
|
||||
* @author Erik Amaru Ortiz <erik@colosa.com>
|
||||
* date Aug 31th, 2010
|
||||
* @copyright (C) 2002 by Colosa Development Team.
|
||||
* This class build biggers PO files without size limit and this not use much
|
||||
* memory that the allowed.
|
||||
*/
|
||||
class i18n_PO
|
||||
{
|
||||
|
||||
private $_file = null;
|
||||
private $_string = '';
|
||||
private $_meta;
|
||||
@@ -55,11 +24,22 @@ class i18n_PO
|
||||
public $flags;
|
||||
public $previousUntranslatedStrings;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the construction of the .po file.
|
||||
*
|
||||
* @return boolean|undefined
|
||||
* @throws Exception
|
||||
*/
|
||||
public function buildInit()
|
||||
{
|
||||
$this->_fp = fopen($this->file, 'w');
|
||||
@@ -82,6 +62,11 @@ class i18n_PO
|
||||
$this->_editingHeader = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start reading the .po file.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function readInit()
|
||||
{
|
||||
$this->_fp = fopen($this->file, 'r');
|
||||
@@ -90,17 +75,23 @@ class i18n_PO
|
||||
throw new Exception('Could\'t open ' . $this->file . ' file');
|
||||
}
|
||||
//skipping comments
|
||||
$this->skipCommets();
|
||||
$this->skipComments();
|
||||
//deaing headers
|
||||
$this->readHeaders();
|
||||
|
||||
$this->translatorComments = Array();
|
||||
$this->extractedComments = Array();
|
||||
$this->references = Array();
|
||||
$this->flags = Array();
|
||||
$this->previousUntranslatedStrings = Array();
|
||||
$this->translatorComments = [];
|
||||
$this->extractedComments = [];
|
||||
$this->references = [];
|
||||
$this->flags = [];
|
||||
$this->previousUntranslatedStrings = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add header information.
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $value
|
||||
*/
|
||||
public function addHeader($id, $value)
|
||||
{
|
||||
if ($this->_editingHeader) {
|
||||
@@ -109,6 +100,11 @@ class i18n_PO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a translator comment.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function addTranslatorComment($str)
|
||||
{
|
||||
$this->headerStroke();
|
||||
@@ -116,6 +112,11 @@ class i18n_PO
|
||||
$this->_writeLine($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a extracted comment.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function addExtractedComment($str)
|
||||
{
|
||||
$this->headerStroke();
|
||||
@@ -123,6 +124,11 @@ class i18n_PO
|
||||
$this->_writeLine($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reference comment.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function addReference($str)
|
||||
{
|
||||
$this->headerStroke();
|
||||
@@ -130,6 +136,11 @@ class i18n_PO
|
||||
$this->_writeLine($reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a flag comment.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function addFlag($str)
|
||||
{
|
||||
$this->headerStroke();
|
||||
@@ -137,6 +148,11 @@ class i18n_PO
|
||||
$this->_writeLine($flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add previous untranslated string.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function addPreviousUntranslatedString($str)
|
||||
{
|
||||
$this->headerStroke();
|
||||
@@ -144,6 +160,12 @@ class i18n_PO
|
||||
$this->_writeLine($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a translation.
|
||||
*
|
||||
* @param string $msgid
|
||||
* @param string $msgstr
|
||||
*/
|
||||
public function addTranslation($msgid, $msgstr)
|
||||
{
|
||||
$this->headerStroke();
|
||||
@@ -152,22 +174,35 @@ class i18n_PO
|
||||
$this->_writeLine('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write line into file.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function _writeLine($str)
|
||||
{
|
||||
$this->_write($str . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into file.
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function _write($str)
|
||||
{
|
||||
fwrite($this->_fp, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare string for add to file.
|
||||
*
|
||||
* @param string $string
|
||||
* @param boolean $reverse
|
||||
* @return string
|
||||
*/
|
||||
public function prepare($string, $reverse = false)
|
||||
{
|
||||
//$string = str_replace('\"', '"', $string);
|
||||
//$string = stripslashes($string);
|
||||
|
||||
|
||||
if ($reverse) {
|
||||
$smap = array('"', "\n", "\t", "\r");
|
||||
$rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r');
|
||||
@@ -180,19 +215,24 @@ class i18n_PO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a header stroke.
|
||||
*/
|
||||
public function headerStroke()
|
||||
{
|
||||
if ($this->_editingHeader) {
|
||||
$this->_editingHeader = false;
|
||||
$this->_writeLine('');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read funtions *
|
||||
*/
|
||||
private function skipCommets()
|
||||
|
||||
/**
|
||||
* Skip comments
|
||||
*/
|
||||
private function skipComments()
|
||||
{
|
||||
$this->_fileComments = '';
|
||||
do {
|
||||
@@ -200,10 +240,14 @@ class i18n_PO
|
||||
$line = fgets($this->_fp);
|
||||
$this->_fileComments .= $line;
|
||||
} while ((substr($line, 0, 1) == '#' || trim($line) == '') && !feof($this->_fp));
|
||||
|
||||
fseek($this->_fp, $lastPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read headers information from .po file.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function readHeaders()
|
||||
{
|
||||
$this->flagEndHeaders = false;
|
||||
@@ -283,19 +327,30 @@ class i18n_PO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translations.
|
||||
*
|
||||
* @return array|boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getTranslation()
|
||||
{
|
||||
|
||||
$flagReadingComments = true;
|
||||
$this->translatorComments = Array();
|
||||
$this->extractedComments = Array();
|
||||
$this->references = Array();
|
||||
$this->flags = Array();
|
||||
$this->translatorComments = [];
|
||||
$this->extractedComments = [];
|
||||
$this->references = [];
|
||||
$this->flags = [];
|
||||
|
||||
//getting the new line
|
||||
while ($flagReadingComments && !$this->flagError) {
|
||||
@@ -388,15 +443,15 @@ class i18n_PO
|
||||
preg_match('/^"(.*)"\s*/s', $this->_fileLine, $match);
|
||||
} while (sizeof($match) == 2);
|
||||
|
||||
/* g::pr($this->translatorComments);
|
||||
g::pr($this->references);
|
||||
g::pr($match);
|
||||
die; */
|
||||
|
||||
return Array('msgid' => trim($msgid), 'msgstr' => trim($msgstr));
|
||||
return [
|
||||
'msgid' => trim($msgid),
|
||||
'msgstr' => trim($msgstr)
|
||||
];
|
||||
}
|
||||
|
||||
//garbage
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->_fp) {
|
||||
@@ -404,4 +459,3 @@ class i18n_PO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
workflow/engine/src/ProcessMaker/Application.php
Normal file
18
workflow/engine/src/ProcessMaker/Application.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker;
|
||||
|
||||
class Application extends \Illuminate\Foundation\Application
|
||||
{
|
||||
/**
|
||||
* Overrides the path to the application "app" directory.
|
||||
*
|
||||
* @param string $path Optionally, a path to append to the app path
|
||||
* @return string
|
||||
*/
|
||||
public function path($path = '')
|
||||
{
|
||||
return $this->basePath . DIRECTORY_SEPARATOR . 'workflow' . DIRECTORY_SEPARATOR .
|
||||
'engine' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'ProcessMaker';
|
||||
}
|
||||
}
|
||||
123
workflow/engine/src/ProcessMaker/Util/Translation/I18Next.php
Normal file
123
workflow/engine/src/ProcessMaker/Util/Translation/I18Next.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Util\Translation;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class I18next
|
||||
* @package ProcessMaker\Util\Translation
|
||||
*/
|
||||
class I18Next
|
||||
{
|
||||
protected $languages;
|
||||
|
||||
/**
|
||||
* I18next constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->languages = new stdClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add translate globals.
|
||||
*
|
||||
* @param string $lan
|
||||
* @param array $translation
|
||||
*/
|
||||
public function setTranslation($lan, array $translation)
|
||||
{
|
||||
foreach ($translation as $index => $item) {
|
||||
$this->languages->{$lan}->translation->{$index} = $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a language.
|
||||
*
|
||||
* @param string $lan
|
||||
* @return stdClass|null
|
||||
*/
|
||||
public function getLanguage($lan)
|
||||
{
|
||||
if (property_exists($this->languages, $lan)) {
|
||||
return $this->languages->{$lan};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add language in object.
|
||||
*
|
||||
* @param string $lan
|
||||
*/
|
||||
public function setLanguage($lan)
|
||||
{
|
||||
if (!property_exists($this->languages, $lan)) {
|
||||
$this->languages->{$lan} = new stdClass();
|
||||
$this->languages->{$lan}->translation = new stdClass();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin.
|
||||
*
|
||||
* @param string $lan
|
||||
* @param string $pluginName
|
||||
* @return stdClass
|
||||
*/
|
||||
public function getPlugin($lan, $pluginName)
|
||||
{
|
||||
return $this->languages->{$lan}->translation->{$pluginName};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin.
|
||||
*
|
||||
* @param string $lan
|
||||
* @param string $pluginName
|
||||
* @param object $plugin
|
||||
*/
|
||||
public function setPlugin($lan, $pluginName, $plugin)
|
||||
{
|
||||
if (!property_exists($this->languages->{$lan}->translation, $pluginName)) {
|
||||
$this->languages->{$lan}->translation->{$pluginName} = new stdClass();
|
||||
}
|
||||
$objMerged = (object) array_merge(
|
||||
(array) $this->languages->{$lan}->translation->{$pluginName}, (array) $plugin
|
||||
);
|
||||
$this->languages->{$lan}->translation->{$pluginName} = $objMerged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate file i18n in json.
|
||||
*
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public function saveJson($filename)
|
||||
{
|
||||
if ($filename) {
|
||||
return file_put_contents($filename, json_encode($this->languages)) !== false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate file i18n in js.
|
||||
*
|
||||
* @param string $pluginName
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public function saveJs($pluginName, $filename)
|
||||
{
|
||||
if ($filename) {
|
||||
$fileContent = "$pluginName = {};";
|
||||
$fileContent .= "$pluginName.i18n = function() { return " . json_encode($this->languages) . "; }";
|
||||
return file_put_contents($filename . ".js", $fileContent) !== false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user