mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 11:22:33 +01:00
Removed old Translation Service + Provider
Was no longer needed due to only being there to perform language extension for de_informal but now this is done by crowdin instead so it's redundant. Same goes for checking and formatting scripts. Also removed comment advising deletion form settings.php language list since this is now auto-copied to languages anyway. Related to #1261
This commit is contained in:
parent
f3a7d58816
commit
f37131a5bf
@ -96,6 +96,7 @@ return [
|
||||
Illuminate\Redis\RedisServiceProvider::class,
|
||||
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
|
||||
Illuminate\Session\SessionServiceProvider::class,
|
||||
Illuminate\Translation\TranslationServiceProvider::class,
|
||||
Illuminate\Validation\ValidationServiceProvider::class,
|
||||
Illuminate\View\ViewServiceProvider::class,
|
||||
Illuminate\Notifications\NotificationServiceProvider::class,
|
||||
@ -109,7 +110,6 @@ return [
|
||||
|
||||
// BookStack replacement service providers (Extends Laravel)
|
||||
BookStack\Providers\PaginationServiceProvider::class,
|
||||
BookStack\Providers\TranslationServiceProvider::class,
|
||||
|
||||
// BookStack custom service providers
|
||||
BookStack\Providers\AuthServiceProvider::class,
|
||||
|
@ -1,31 +0,0 @@
|
||||
<?php namespace BookStack\Providers;
|
||||
|
||||
use BookStack\Translation\Translator;
|
||||
|
||||
class TranslationServiceProvider extends \Illuminate\Translation\TranslationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerLoader();
|
||||
|
||||
$this->app->singleton('translator', function ($app) {
|
||||
$loader = $app['translation.loader'];
|
||||
|
||||
// When registering the translator component, we'll need to set the default
|
||||
// locale as well as the fallback locale. So, we'll grab the application
|
||||
// configuration so we can easily get both of these values from there.
|
||||
$locale = $app['config']['app.locale'];
|
||||
|
||||
$trans = new Translator($loader, $locale);
|
||||
|
||||
$trans->setFallback($app['config']['app.fallback_locale']);
|
||||
|
||||
return $trans;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
<?php namespace BookStack\Translation;
|
||||
|
||||
class Translator extends \Illuminate\Translation\Translator
|
||||
{
|
||||
|
||||
/**
|
||||
* Mapping of locales to their base locales
|
||||
* @var array
|
||||
*/
|
||||
protected $baseLocaleMap = [
|
||||
'de_informal' => 'de',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the translation for a given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $replace
|
||||
* @param string $locale
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function trans($key, array $replace = [], $locale = null)
|
||||
{
|
||||
$translation = $this->get($key, $replace, $locale);
|
||||
|
||||
if (is_array($translation)) {
|
||||
$translation = $this->mergeBackupTranslations($translation, $key, $locale);
|
||||
}
|
||||
|
||||
return $translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the fallback translations, and base translations if existing,
|
||||
* into the provided core key => value array of translations content.
|
||||
* @param array $translationArray
|
||||
* @param string $key
|
||||
* @param null $locale
|
||||
* @return array
|
||||
*/
|
||||
protected function mergeBackupTranslations(array $translationArray, string $key, $locale = null)
|
||||
{
|
||||
$fallback = $this->get($key, [], $this->fallback);
|
||||
$baseLocale = $this->getBaseLocale($locale ?? $this->locale);
|
||||
$baseTranslations = $baseLocale ? $this->get($key, [], $baseLocale) : [];
|
||||
|
||||
return array_replace_recursive($fallback, $baseTranslations, $translationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of locales to be checked.
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return array
|
||||
*/
|
||||
protected function localeArray($locale)
|
||||
{
|
||||
$primaryLocale = $locale ?: $this->locale;
|
||||
return array_filter([$primaryLocale, $this->getBaseLocale($primaryLocale), $this->fallback]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale to extend for the given locale.
|
||||
*
|
||||
* @param string $locale
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getBaseLocale($locale)
|
||||
{
|
||||
return $this->baseLocaleMap[$locale] ?? null;
|
||||
}
|
||||
}
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'تم ربط حساب :socialAccount بملفك بنجاح.',
|
||||
'users_social_disconnected' => 'تم فصل حساب :socialAccount من ملفك بنجاح.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -1,114 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Compares translation files to find missing and redundant content.
|
||||
*/
|
||||
|
||||
$args = array_slice($argv, 1);
|
||||
|
||||
if (count($args) === 0) {
|
||||
errorOut("Please provide a language code as the first argument (./check.php fr)");
|
||||
}
|
||||
|
||||
|
||||
// Get content from files
|
||||
$lang = formatLang($args[0]);
|
||||
$enContent = loadLang('en');
|
||||
$langContent = loadLang($lang);
|
||||
|
||||
if (count($langContent) === 0) {
|
||||
errorOut("No language content found for '{$lang}'");
|
||||
}
|
||||
|
||||
info("Checking '{$lang}' translation content against 'en'");
|
||||
|
||||
// Track missing lang strings
|
||||
$missingLangStrings = [];
|
||||
foreach ($enContent as $enKey => $enStr) {
|
||||
if (strpos($enKey, 'settings.language_select.') === 0) {
|
||||
unset($langContent[$enKey]);
|
||||
continue;
|
||||
}
|
||||
if (!isset($langContent[$enKey])) {
|
||||
$missingLangStrings[$enKey] = $enStr;
|
||||
continue;
|
||||
}
|
||||
unset($langContent[$enKey]);
|
||||
}
|
||||
|
||||
if (count($missingLangStrings) > 0) {
|
||||
info("\n========================");
|
||||
info("Missing language content");
|
||||
info("========================");
|
||||
outputFlatArray($missingLangStrings, $lang);
|
||||
}
|
||||
|
||||
if (count($langContent) > 0) {
|
||||
info("\n==========================");
|
||||
info("Redundant language content");
|
||||
info("==========================");
|
||||
outputFlatArray($langContent, $lang);
|
||||
}
|
||||
|
||||
function outputFlatArray($arr, $lang) {
|
||||
$grouped = [];
|
||||
foreach ($arr as $key => $val) {
|
||||
$explodedKey = explode('.', $key);
|
||||
$group = $explodedKey[0];
|
||||
$path = implode('.', array_slice($explodedKey, 1));
|
||||
if (!isset($grouped[$group])) $grouped[$group] = [];
|
||||
$grouped[$group][$path] = $val;
|
||||
}
|
||||
foreach ($grouped as $filename => $arr) {
|
||||
echo "\e[36m" . $lang . '/' . $filename . ".php\e[0m\n";
|
||||
echo json_encode($arr, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
function formatLang($lang) {
|
||||
$langParts = explode('_', strtoupper($lang));
|
||||
$langParts[0] = strtolower($langParts[0]);
|
||||
return implode('_', $langParts);
|
||||
}
|
||||
|
||||
function loadLang(string $lang) {
|
||||
$dir = __DIR__ . "/{$lang}";
|
||||
if (!file_exists($dir)) {
|
||||
errorOut("Expected directory '{$dir}' does not exist");
|
||||
}
|
||||
$files = scandir($dir);
|
||||
$data = [];
|
||||
foreach ($files as $file) {
|
||||
if (substr($file, -4) !== '.php') continue;
|
||||
$fileData = include ($dir . '/' . $file);
|
||||
$name = substr($file, 0, -4);
|
||||
$data[$name] = $fileData;
|
||||
}
|
||||
return flattenArray($data);
|
||||
}
|
||||
|
||||
function flattenArray(array $arr) {
|
||||
$data = [];
|
||||
foreach ($arr as $key => $arrItem) {
|
||||
if (!is_array($arrItem)) {
|
||||
$data[$key] = $arrItem;
|
||||
continue;
|
||||
}
|
||||
|
||||
$toUse = flattenArray($arrItem);
|
||||
foreach ($toUse as $innerKey => $item) {
|
||||
$data[$key . '.' . $innerKey] = $item;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function info($text) {
|
||||
echo "\e[34m" . $text . "\e[0m\n";
|
||||
}
|
||||
|
||||
function errorOut($text) {
|
||||
echo "\e[31m" . $text . "\e[0m\n";
|
||||
exit(1);
|
||||
}
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'Účet :socialAccount byl úspěšně přidružen k vašemu profilu.',
|
||||
'users_social_disconnected' => 'Přidružení účtu :socialAccount k vašemu profilu bylo úspěšně zrušeno.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -138,9 +138,8 @@ Hinweis: Benutzer können ihre E-Mail Adresse nach erfolgreicher Registrierung
|
||||
'users_social_connected' => ':socialAccount-Konto wurde erfolgreich mit dem Profil verknüpft.',
|
||||
'users_social_disconnected' => ':socialAccount-Konto wurde erfolgreich vom Profil gelöst.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -138,9 +138,8 @@ Hinweis: Benutzer können ihre E-Mail Adresse nach erfolgreicher Registrierung
|
||||
'users_social_connected' => ':socialAccount-Konto wurde erfolgreich mit dem Profil verknüpft.',
|
||||
'users_social_disconnected' => ':socialAccount-Konto wurde erfolgreich vom Profil gelöst.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount account was successfully attached to your profile.',
|
||||
'users_social_disconnected' => ':socialAccount account was successfully disconnected from your profile.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'La cuenta :socialAccount ha sido añadida éxitosamente a su perfil.',
|
||||
'users_social_disconnected' => 'La cuenta :socialAccount ha sido desconectada éxitosamente de su perfil.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -136,9 +136,8 @@ return [
|
||||
'users_social_connected' => 'La cuenta :socialAccount ha sido exitosamente añadida a su perfil.',
|
||||
'users_social_disconnected' => 'La cuenta :socialAccount ha sido desconectada exitosamente de su perfil.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -1,330 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Format a language file in the same way as the EN equivalent.
|
||||
* Matches the line numbers of translated content.
|
||||
* Potentially destructive, Ensure you have a backup of your translation content before running.
|
||||
*/
|
||||
|
||||
$args = array_slice($argv, 1);
|
||||
|
||||
if (count($args) < 2) {
|
||||
errorOut("Please provide a language code as the first argument and a translation file name, or '--all', as the second (./format.php fr activities)");
|
||||
}
|
||||
|
||||
$lang = formatLocale($args[0]);
|
||||
$fileName = explode('.', $args[1])[0];
|
||||
$fileNames = [$fileName];
|
||||
if ($fileName === '--all') {
|
||||
$fileNames = getTranslationFileNames();
|
||||
}
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
$formatted = formatFileContents($lang, $fileName);
|
||||
writeLangFile($lang, $fileName, $formatted);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format the contents of a single translation file in the given language.
|
||||
* @param string $lang
|
||||
* @param string $fileName
|
||||
* @return string
|
||||
*/
|
||||
function formatFileContents(string $lang, string $fileName) : string {
|
||||
$enLines = loadLangFileLines('en', $fileName);
|
||||
$langContent = loadLang($lang, $fileName);
|
||||
$enContent = loadLang('en', $fileName);
|
||||
|
||||
// Calculate the longest top-level key length
|
||||
$longestKeyLength = calculateKeyPadding($enContent);
|
||||
|
||||
// Start formatted content
|
||||
$formatted = [];
|
||||
$mode = 'header';
|
||||
$skipArray = false;
|
||||
$arrayKeys = [];
|
||||
|
||||
foreach ($enLines as $index => $line) {
|
||||
$trimLine = trim($line);
|
||||
if ($mode === 'header') {
|
||||
$formatted[$index] = $line;
|
||||
if (str_replace(' ', '', $trimLine) === 'return[') $mode = 'body';
|
||||
}
|
||||
|
||||
if ($mode === 'body') {
|
||||
$matches = [];
|
||||
$arrayEndMatch = preg_match('/]\s*,\s*$/', $trimLine);
|
||||
|
||||
if ($skipArray) {
|
||||
if ($arrayEndMatch) $skipArray = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Comment to ignore
|
||||
if (strpos($trimLine, '//!') === 0) {
|
||||
$formatted[$index] = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Comment
|
||||
if (strpos($trimLine, '//') === 0) {
|
||||
$formatted[$index] = "\t" . $trimLine;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Arrays
|
||||
$arrayStartMatch = preg_match('/^\'(.*)\'\s+?=>\s+?\[(\],)?\s*?$/', $trimLine, $matches);
|
||||
|
||||
$indent = count($arrayKeys) + 1;
|
||||
if ($arrayStartMatch === 1) {
|
||||
if ($fileName === 'settings' && $matches[1] === 'language_select') {
|
||||
$skipArray = true;
|
||||
continue;
|
||||
}
|
||||
$arrayKeys[] = $matches[1];
|
||||
$formatted[$index] = str_repeat(" ", $indent * 4) . str_pad("'{$matches[1]}'", $longestKeyLength) . "=> [";
|
||||
if ($arrayEndMatch !== 1) continue;
|
||||
}
|
||||
if ($arrayEndMatch === 1) {
|
||||
unsetArrayByKeys($langContent, $arrayKeys);
|
||||
array_pop($arrayKeys);
|
||||
if (isset($formatted[$index])) {
|
||||
$formatted[$index] .= '],';
|
||||
} else {
|
||||
$formatted[$index] = str_repeat(" ", ($indent-1) * 4) . "],";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Translation
|
||||
$translationMatch = preg_match('/^\'(.*)\'\s+?=>\s+?[\'"](.*)?[\'"].+?$/', $trimLine, $matches);
|
||||
if ($translationMatch === 1) {
|
||||
$key = $matches[1];
|
||||
$keys = array_merge($arrayKeys, [$key]);
|
||||
$langVal = getTranslationByKeys($langContent, $keys);
|
||||
if (empty($langVal)) continue;
|
||||
|
||||
$keyPad = $longestKeyLength;
|
||||
if (count($arrayKeys) === 0) {
|
||||
unset($langContent[$key]);
|
||||
} else {
|
||||
$keyPad = calculateKeyPadding(getTranslationByKeys($enContent, $arrayKeys));
|
||||
}
|
||||
|
||||
$formatted[$index] = formatTranslationLine($key, $langVal, $indent, $keyPad);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Fill missing lines
|
||||
$arraySize = max(array_keys($formatted));
|
||||
$formatted = array_replace(array_fill(0, $arraySize, ''), $formatted);
|
||||
|
||||
// Add remaining translations
|
||||
$langContent = array_filter($langContent, function($item) {
|
||||
return !is_null($item) && !empty($item);
|
||||
});
|
||||
if (count($langContent) > 0) {
|
||||
$formatted[] = '';
|
||||
$formatted[] = "\t// Unmatched";
|
||||
}
|
||||
foreach ($langContent as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$formatted[] = formatTranslationArray($key, $value);
|
||||
} else {
|
||||
$formatted[] = formatTranslationLine($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Add end line
|
||||
$formatted[] = '];';
|
||||
return implode("\n", $formatted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a translation line.
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param int $indent
|
||||
* @param int $keyPad
|
||||
* @return string
|
||||
*/
|
||||
function formatTranslationLine(string $key, string $value, int $indent = 1, int $keyPad = 1) : string {
|
||||
$start = str_repeat(" ", $indent * 4) . str_pad("'{$key}'", $keyPad, ' ');
|
||||
if (strpos($value, "\n") !== false) {
|
||||
$escapedValue = '"' . str_replace("\n", '\n', $value) . '"';
|
||||
$escapedValue = '"' . str_replace('"', '\"', $escapedValue) . '"';
|
||||
} else {
|
||||
$escapedValue = "'" . str_replace("'", "\\'", $value) . "'";
|
||||
}
|
||||
return "{$start} => {$escapedValue},";
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the longest key in the array and provide the length
|
||||
* for all keys to be used when printed.
|
||||
* @param array $array
|
||||
* @return int
|
||||
*/
|
||||
function calculateKeyPadding(array $array) : int {
|
||||
$top = 0;
|
||||
foreach ($array as $key => $value) {
|
||||
$keyLen = strlen($key);
|
||||
$top = max($top, $keyLen);
|
||||
}
|
||||
return min(35, $top + 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an translation array with the given key.
|
||||
* Simply prints as an old-school php array.
|
||||
* Used as a last-resort backup to save unused translations.
|
||||
* @param string $key
|
||||
* @param array $array
|
||||
* @return string
|
||||
*/
|
||||
function formatTranslationArray(string $key, array $array) : string {
|
||||
$arrayPHP = var_export($array, true);
|
||||
return " '{$key}' => {$arrayPHP},";
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a string translation value within a multi-dimensional array
|
||||
* by traversing the given array of keys.
|
||||
* @param array $translations
|
||||
* @param array $keys
|
||||
* @return string|array
|
||||
*/
|
||||
function getTranslationByKeys(array $translations, array $keys) {
|
||||
$val = $translations;
|
||||
foreach ($keys as $key) {
|
||||
$val = $val[$key] ?? '';
|
||||
if ($val === '') return '';
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset an inner item of a multi-dimensional array by
|
||||
* traversing the given array of keys.
|
||||
* @param array $input
|
||||
* @param array $keys
|
||||
*/
|
||||
function unsetArrayByKeys(array &$input, array $keys) {
|
||||
$val = &$input;
|
||||
$lastIndex = count($keys) - 1;
|
||||
foreach ($keys as $index => &$key) {
|
||||
if ($index === $lastIndex && is_array($val)) {
|
||||
unset($val[$key]);
|
||||
}
|
||||
if (!is_array($val)) return;
|
||||
$val = &$val[$key] ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the given content to a translation file.
|
||||
* @param string $lang
|
||||
* @param string $fileName
|
||||
* @param string $content
|
||||
*/
|
||||
function writeLangFile(string $lang, string $fileName, string $content) {
|
||||
$path = __DIR__ . "/{$lang}/{$fileName}.php";
|
||||
if (!file_exists($path)) {
|
||||
errorOut("Expected translation file '{$path}' does not exist");
|
||||
}
|
||||
file_put_contents($path, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the contents of a language file as an array of text lines.
|
||||
* @param string $lang
|
||||
* @param string $fileName
|
||||
* @return array
|
||||
*/
|
||||
function loadLangFileLines(string $lang, string $fileName) : array {
|
||||
$path = __DIR__ . "/{$lang}/{$fileName}.php";
|
||||
if (!file_exists($path)) {
|
||||
errorOut("Expected translation file '{$path}' does not exist");
|
||||
}
|
||||
$lines = explode("\n", file_get_contents($path));
|
||||
return array_map(function($line) {
|
||||
return trim($line, "\r");
|
||||
}, $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the contents of a language file
|
||||
* @param string $lang
|
||||
* @param string $fileName
|
||||
* @return array
|
||||
*/
|
||||
function loadLang(string $lang, string $fileName) : array {
|
||||
$path = __DIR__ . "/{$lang}/{$fileName}.php";
|
||||
if (!file_exists($path)) {
|
||||
errorOut("Expected translation file '{$path}' does not exist");
|
||||
}
|
||||
|
||||
$fileData = include($path);
|
||||
return $fileData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an array containing the names of all translation files without the extension.
|
||||
* @return array
|
||||
*/
|
||||
function getTranslationFileNames() : array {
|
||||
$dir = __DIR__ . "/en";
|
||||
if (!file_exists($dir)) {
|
||||
errorOut("Expected directory '{$dir}' does not exist");
|
||||
}
|
||||
$files = scandir($dir);
|
||||
$fileNames = [];
|
||||
foreach ($files as $file) {
|
||||
if (substr($file, -4) === '.php') {
|
||||
$fileNames[] = substr($file, 0, strlen($file) - 4);
|
||||
}
|
||||
}
|
||||
return $fileNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a locale to follow the lowercase_UPERCASE standard
|
||||
* @param string $lang
|
||||
* @return string
|
||||
*/
|
||||
function formatLocale(string $lang) : string {
|
||||
$langParts = explode('_', strtoupper($lang));
|
||||
$langParts[0] = strtolower($langParts[0]);
|
||||
return implode('_', $langParts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump a variable then die.
|
||||
* @param $content
|
||||
*/
|
||||
function dd($content) {
|
||||
print_r($content);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out some information text in blue
|
||||
* @param $text
|
||||
*/
|
||||
function info($text) {
|
||||
echo "\e[34m" . $text . "\e[0m\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out an error in red and exit.
|
||||
* @param $text
|
||||
*/
|
||||
function errorOut($text) {
|
||||
echo "\e[31m" . $text . "\e[0m\n";
|
||||
exit(1);
|
||||
}
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'Votre compte :socialAccount a été ajouté avec succès.',
|
||||
'users_social_disconnected' => 'Votre compte :socialAccount a été déconnecté avec succès',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount fiók sikeresen csatlakoztatva a profilhoz.',
|
||||
'users_social_disconnected' => ':socialAccount fiók sikeresen lecsatlakoztatva a profilról.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'L\'account :socialAccount è stato connesso correttamente al tuo profilo.',
|
||||
'users_social_disconnected' => 'L\'account :socialAccount è stato disconnesso correttamente dal tuo profilo.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => '「:socialAccount」がプロフィールに接続されました。',
|
||||
'users_social_disconnected' => '「:socialAccount」がプロフィールから接続解除されました。',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount 계정이 당신의 프로필에 연결되었습니다.',
|
||||
'users_social_disconnected' => ':socialAccount 계정이 당신의 프로필에서 연결해제되었습니다.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount account is succesvol aan je profiel gekoppeld.',
|
||||
'users_social_disconnected' => ':socialAccount account is succesvol ontkoppeld van je profiel.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount zostało dodane do Twojego profilu.',
|
||||
'users_social_disconnected' => ':socialAccount zostało odłączone od Twojego profilu.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'Conta :socialAccount foi conectada com sucesso ao seu perfil.',
|
||||
'users_social_disconnected' => 'Conta :socialAccount foi desconectada com sucesso de seu perfil.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount аккаунт упешно подключен к вашему профилю.',
|
||||
'users_social_disconnected' => ':socialAccount аккаунт успешно отключен от вашего профиля.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount účet bol úspešne pripojený k Vášmu profilu.',
|
||||
'users_social_disconnected' => ':socialAccount účet bol úspešne odpojený od Vášho profilu.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount har kopplats till ditt konto.',
|
||||
'users_social_disconnected' => ':socialAccount har kopplats bort från ditt konto.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount hesabı profilinize başarıyla bağlandı.',
|
||||
'users_social_disconnected' => ':socialAccount hesabınızın profilinizle ilişiği başarıyla kesildi.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => 'Обліковий запис :socialAccount успішно додано до вашого профілю.',
|
||||
'users_social_disconnected' => 'Обліковий запис :socialAccount був успішно відключений від вашого профілю.',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount 账户已经成功绑定到您的资料。',
|
||||
'users_social_disconnected' => ':socialAccount 账户已经成功解除绑定。',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -135,9 +135,8 @@ return [
|
||||
'users_social_connected' => ':socialAccount 帳號已經成功連結到您的資料。',
|
||||
'users_social_disconnected' => ':socialAccount 帳號已經成功解除連結。',
|
||||
|
||||
//! Since these labels are already localized this array does not need to be
|
||||
//! translated in the language-specific files.
|
||||
//! DELETE BELOW IF COPIED FROM EN
|
||||
//! If editing translations files directly please ignore this in all
|
||||
//! languages apart from en. Content will be auto-copied from en.
|
||||
//!////////////////////////////////
|
||||
'language_select' => [
|
||||
'en' => 'English',
|
||||
|
@ -66,21 +66,4 @@ class LanguageTest extends TestCase
|
||||
$this->assertTrue(config('app.rtl'), "App RTL config should have been set to true by middleware");
|
||||
}
|
||||
|
||||
public function test_de_informal_falls_base_to_de()
|
||||
{
|
||||
// Base de back value
|
||||
$deBack = trans()->get('common.cancel', [], 'de', false);
|
||||
$this->assertEquals('Abbrechen', $deBack);
|
||||
// Ensure de_informal has no value set
|
||||
$this->assertEquals('common.cancel', trans()->get('common.cancel', [], 'de_informal', false));
|
||||
// Ensure standard trans falls back to de
|
||||
$this->assertEquals($deBack, trans('common.cancel', [], 'de_informal'));
|
||||
// Ensure de_informal gets its own values where set
|
||||
$deEmailActionHelp = trans()->get('common.email_action_help', [], 'de', false);
|
||||
$enEmailActionHelp = trans()->get('common.email_action_help', [], 'en', false);
|
||||
$deInformalEmailActionHelp = trans()->get('common.email_action_help', [], 'de_informal', false);
|
||||
$this->assertNotEquals($deEmailActionHelp, $deInformalEmailActionHelp);
|
||||
$this->assertNotEquals($enEmailActionHelp, $deInformalEmailActionHelp);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user