Skip to content

Commit

Permalink
Localizations load from CAKEPHP helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed Feb 22, 2023
1 parent 99da477 commit 06930ed
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
74 changes: 74 additions & 0 deletions app/src/View/Helper/VueHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* COmanage Registry Vue Helper
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace App\View\Helper;

use Cake\I18n\FrozenTime;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\I18n\I18n;

class VueHelper extends Helper {
private array $locales_list = [
'field' => [
'login',
'primary',
'datepicker.hour',
'unverified'
],
'information' => [
'global.value.none',
'datepicker.hour'
]
];

/**
* Helper which will produce an array of configured locales
*
* @param string $lang The language of the locale
*
* @return array []
* @since COmanage Registry v5.0.0
*/

public function locales(string $lang = 'en_US'): array {

I18n::setLocale($lang);

$locales = [];
foreach ($this->locales_list as $domain => $key_list) {
foreach ($key_list as $key) {
$locales[$key] = __d($domain, $key);
}
}

return $locales;
}

}
12 changes: 4 additions & 8 deletions app/templates/element/mveaJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

// Get the CSRF Token in JavaScript
$token = $this->request->getAttribute('csrfToken');
// Load my helper functions
$vueHelper = $this->loadHelper('Vue');


// Create an MVEA component - typically this is represented as a card on a canvas page
?>
Expand All @@ -59,14 +62,7 @@
mveaController: '<?= $mveaController ?>',
webroot: '<?= $this->request->getAttribute('webroot') ?>'
},
txt: {
login: '<?= __d('field','login') ?>',
none: '<?= __d('information','global.value.none') ?>',
primary: '<?= __d('field', 'primary') ?>',
status: '<?= __d('field', 'datepicker.hour') ?>',
unverified: '<?= __d('field', 'unverified') ?>',
visit: '<?= __d('information', 'global.visit.link') ?>'
},
txt: JSON.parse('<?= json_encode($vueHelper->locales()) ?>'),
isLoading: true
}
},
Expand Down

0 comments on commit 06930ed

Please sign in to comment.