MOBILE-3565 scripts: Add language scripts

main
Pau Ferrer Ocaña 2020-11-05 15:04:17 +01:00
parent 51fba1f5d8
commit 921e2f18f7
6 changed files with 3146 additions and 0 deletions

View File

@ -0,0 +1,327 @@
#!/bin/bash
source "functions.sh"
#Saves or updates a key on langindex_old.json
function save_key {
local key=$1
local found=$2
print_ok "$key=$found"
echo "{\"$key\": \"$found\"}" > langindex_old.json
jq -s '.[0] + .[1]' langindex.json langindex_old.json > langindex_new.json
mv langindex_new.json langindex.json
}
#Removes a key on langindex_old.json
function remove_key {
local key=$1
cat langindex.json | jq 'del(."'$key'")' > langindex_new.json
mv langindex_new.json langindex.json
print_ok "Deleted unused key $key"
}
#Check if and i exists in php file
function exists_in_file {
local file=$1
local id=$2
file=`echo $file | sed s/^mod_workshop_assessment/workshopform/1`
file=`echo $file | sed s/^mod_assign_/assign/1`
file=`echo $file | sed s/^mod_//1`
completeFile="$LANGPACKSFOLDER/en/$file.php"
if [ -f "$completeFile" ]; then
coincidence=`grep "string\[\'$id\'\]" $completeFile`
if [ ! -z "$coincidence" ]; then
found=$file
return
fi
fi
found=0
}
#Checks if a key exists on the original local_moodlemobileapp.php
function exists_in_mobile {
local file='local_moodlemobileapp'
exists_in_file $file $key
}
function do_match {
match=$1
filematch=""
coincidence=`grep "$match" $LANGPACKSFOLDER/en/*.php | wc -l`
if [ $coincidence -eq 1 ]; then
filematch=`grep "$match" $LANGPACKSFOLDER/en/*.php | cut -d'/' -f5 | cut -d'.' -f1`
exists_in_file $filematch $plainid
elif [ $coincidence -gt 0 ] && [ "$#" -gt 1 ]; then
print_message $2
tput setaf 6
grep "$match" $LANGPACKSFOLDER/en/*.php
fi
}
#Find if the id or the value can be found on files to help providing a solution.
function find_matches {
do_match "string\[\'$plainid\'\] = \'$value\'" "Found EXACT match for $key in the following paths"
if [ $coincidence -gt 0 ]; then
case=1
return
fi
do_match " = \'$value\'" "Found some string VALUES for $key in the following paths"
if [ $coincidence -gt 0 ]; then
case=2
return
fi
do_match "string\[\'$plainid\'\]" "Found some string KEYS for $key in the following paths, value $value"
if [ $coincidence -gt 0 ]; then
case=3
return
fi
print_message "No match found for $key add it to local_moodlemobileapp"
save_key $key "local_moodlemobileapp"
}
function find_single_matches {
do_match "string\[\'$plainid\'\] = \'$value\'"
if [ ! -z $filematch ] && [ $found != 0 ]; then
case=1
return
fi
do_match " = \'$value\'"
if [ ! -z $filematch ] && [ $filematch != 'local_moodlemobileapp' ]; then
case=2
print_message "Found some string VALUES for $key in the following paths $filematch"
tput setaf 6
grep "$match" $LANGPACKSFOLDER/en/*.php
return
fi
do_match "string\[\'$plainid\'\]"
if [ ! -z $filematch ] && [ $found != 0 ]; then
case=3
return
fi
}
#Tries to gues the file where the id will be found.
function guess_file {
local key=$1
local value=$2
local type=`echo $key | cut -d'.' -f1`
local component=`echo $key | cut -d'.' -f2`
local plainid=`echo $key | cut -d'.' -f3-`
if [ -z "$plainid" ]; then
plainid=$component
component='moodle'
fi
exists_in_file $component $plainid
if [ $found == 0 ]; then
tempid=`echo $plainid | sed s/^mod_//1`
if [ $component == 'moodle' ] && [ "$tempid" != "$plainid" ]; then
exists_in_file $plainid pluginname
if [ $found != 0 ]; then
found=$found/pluginname
fi
fi
fi
# Not found in file, try in local_moodlemobileapp
if [ $found == 0 ]; then
exists_in_mobile
fi
# Still not found, if only found in one file, use it.
if [ $found == 0 ]; then
find_single_matches
fi
# Last fallback.
if [ $found == 0 ]; then
exists_in_file 'moodle' $plainid
fi
if [ $found == 0 ]; then
find_matches
else
save_key $key $found
fi
}
function current_translation_exists {
local key=$1
local current=$2
local file=$3
plainid=`echo $key | cut -d'.' -f3-`
if [ -z "$plainid" ]; then
plainid=`echo $key | cut -d'.' -f2`
fi
local currentFile=`echo $current | cut -d'/' -f1`
local currentStr=`echo $current | cut -d'/' -f2-`
if [ $currentFile == $current ]; then
currentStr=$plainid
fi
exists_in_file $currentFile $currentStr
if [ $found == 0 ]; then
# Translation not found.
exec="jq -r .\"$key\" $file"
value=`$exec`
print_error "Translation of '$currentStr' not found in '$currentFile'"
guess_file $key "$value"
fi
}
#Finds if there's a better file where to get the id from.
function find_better_file {
local key=$1
local value=$2
local current=$3
local type=`echo $key | cut -d'.' -f1`
local component=`echo $key | cut -d'.' -f2`
local plainid=`echo $key | cut -d'.' -f3-`
if [ -z "$plainid" ]; then
plainid=$component
component='moodle'
fi
local currentFile=`echo $current | cut -d'/' -f1`
local currentStr=`echo $current | cut -d'/' -f2-`
if [ $currentFile == $current ]; then
currentStr=$plainid
fi
exists_in_file $component $plainid
if [ $found != 0 ] && [ $currentStr == $plainid ]; then
if [ $found != $currentFile ]; then
print_ok "Key '$key' found in component, no need to replace old '$current'"
fi
return
fi
# Still not found, if only found in one file, use it.
if [ $found == 0 ]; then
find_single_matches
fi
if [ $found != 0 ] && [ $found != $currentFile ] && [ $case -lt 3 ]; then
print_message "Indexed string '$key' found in '$found' better than '$current'"
return
fi
if [ $currentFile == 'local_moodlemobileapp' ]; then
exists_in_mobile
else
exists_in_file $currentFile $currentStr
fi
if [ $found == 0 ]; then
print_error "Indexed string '$key' not found on current place '$current'"
if [ $currentFile != 'local_moodlemobileapp' ]; then
print_error "Execute this on AMOS
CPY [$currentStr,$currentFile],[$key,local_moodlemobileapp]"
save_key $key "local_moodlemobileapp"
fi
fi
}
# Parses the file.
function parse_file {
findbetter=$2
keys=`jq -r 'keys[]' $1`
for key in $keys; do
# Check if already parsed.
exec="jq -r .\"$key\" langindex.json"
found=`$exec`
if [ -z "$found" ] || [ "$found" == 'null' ]; then
exec="jq -r .\"$key\" $1"
value=`$exec`
guess_file $key "$value"
else
if [ "$found" == 'donottranslate' ]; then
# Do nothing since is not translatable.
continue
elif [ ! -z "$findbetter" ]; then
exec="jq -r .\"$key\" $1"
value=`$exec`
find_better_file "$key" "$value" "$found"
elif [ "$found" != 'local_moodlemobileapp' ]; then
current_translation_exists "$key" "$found" "$1"
fi
fi
done
# Do some cleanup
langkeys=`jq -r 'keys[]' langindex.json`
findkeys="${keys[@]}"
for key in $langkeys; do
# Check if already used.
array_contains "$key" "$findkeys"
if [ -z "$found" ] || [ "$found" == 'null' ]; then
remove_key $key
fi
done
}
# Checks if an array contains an string.
function array_contains {
local hayjack=$2
local needle=$1
found=''
for i in $hayjack; do
if [ "$i" == "$needle" ] ; then
found=$i
return
fi
done
}
print_title 'Generating language from code...'
gulp lang
print_title 'Getting languages'
git clone https://git.in.moodle.com/moodle/moodle-langpacks.git $LANGPACKSFOLDER
pushd $LANGPACKSFOLDER
BRANCHES=($(git branch -r --format="%(refname:lstrip=3)" --sort="refname" | grep MOODLE_))
BRANCH=${BRANCHES[${#BRANCHES[@]}-1]}
git checkout $BRANCH
git pull
popd
print_title 'Processing file'
#Create langindex.json if not exists.
if [ ! -f 'langindex.json' ]; then
echo "{}" > langindex.json
fi
findbetter=$1
parse_file '../src/assets/lang/en.json' $findbetter
echo
jq -S --indent 2 -s '.[0]' langindex.json > langindex_new.json
mv langindex_new.json langindex.json
rm langindex_old.json
print_ok 'All done!'

View File

@ -0,0 +1,67 @@
#!/bin/bash
LANGPACKSFOLDER='../../moodle-langpacks'
function check_success_exit {
if [ $? -ne 0 ]; then
print_error "$1"
exit 1
elif [ "$#" -gt 1 ]; then
print_ok "$2"
fi
}
function check_success {
if [ $? -ne 0 ]; then
print_error "$1"
elif [ "$#" -gt 1 ]; then
print_ok "$2"
fi
}
function print_success {
if [ $? -ne 0 ]; then
print_message "$1"
$3=0
else
print_ok "$2"
fi
}
function print_error {
tput setaf 1; echo " ERROR: $1"; tput sgr0
}
function print_ok {
tput setaf 2; echo " OK: $1"; tput sgr0
echo
}
function print_message {
tput setaf 3; echo "-------- $1"; tput sgr0
echo
}
function print_title {
stepnumber=$(($stepnumber + 1))
echo
tput setaf 5; echo "$stepnumber $1"; tput sgr0
tput setaf 5; echo '=================='; tput sgr0
}
function telegram_notify {
if [ ! -z $TELEGRAM_APIKEY ] && [ ! -z $TELEGRAM_CHATID ] ; then
MESSAGE="Travis error: $1%0ABranch: $TRAVIS_BRANCH%0ARepo: $TRAVIS_REPO_SLUG"
URL="https://api.telegram.org/bot$TELEGRAM_APIKEY/sendMessage"
curl -s -X POST $URL -d chat_id=$TELEGRAM_CHATID -d text="$MESSAGE"
fi
}
function notify_on_error_exit {
if [ $? -ne 0 ]; then
print_error "$1"
telegram_notify "$1"
exit 1
fi
}

View File

@ -0,0 +1,474 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Helper functions converting moodle strings to json.
*/
function detect_languages($languages, $keys) {
echo "\n\n\n";
$all_languages = glob(LANGPACKSFOLDER.'/*' , GLOB_ONLYDIR);
function get_lang_from_dir($dir) {
return str_replace('_', '-', explode('/', $dir)[3]);
}
function get_lang_not_wp($langname) {
return (substr($langname, -3) !== '-wp');
}
$all_languages = array_map('get_lang_from_dir', $all_languages);
$all_languages = array_filter($all_languages, 'get_lang_not_wp');
$detect_lang = array_diff($all_languages, $languages);
$new_langs = array();
foreach ($detect_lang as $lang) {
reset_translations_strings();
$new = detect_lang($lang, $keys);
if ($new) {
$new_langs[$lang] = $lang;
}
}
return $new_langs;
}
function build_languages($languages, $keys, $added_langs = []) {
// Process the languages.
foreach ($languages as $lang) {
reset_translations_strings();
$ok = build_lang($lang, $keys);
if ($ok) {
$added_langs[$lang] = $lang;
}
}
return $added_langs;
}
function get_langindex_keys() {
$local = 0;
// Process the index file, just once.
$keys = file_get_contents('langindex.json');
$keys = (array) json_decode($keys);
foreach ($keys as $key => $value) {
$map = new StdClass();
if ($value == 'local_moodlemobileapp') {
$map->file = $value;
$map->string = $key;
$local++;
} else {
$exp = explode('/', $value, 2);
$map->file = $exp[0];
if (count($exp) == 2) {
$map->string = $exp[1];
} else {
$exp = explode('.', $key, 3);
if (count($exp) == 3) {
$map->string = $exp[2];
} else {
$map->string = $exp[1];
}
}
}
$keys[$key] = $map;
}
$total = count($keys);
echo "Total strings to translate $total ($local local)\n";
return $keys;
}
function add_langs_to_config($langs, $config) {
$changed = false;
$config_langs = get_object_vars($config['languages']);
foreach ($langs as $lang) {
if (!isset($config_langs[$lang])) {
$langfoldername = str_replace('-', '_', $lang);
$string = [];
include(LANGPACKSFOLDER.'/'.$langfoldername.'/langconfig.php');
$config['languages']->$lang = $string['thislanguage'];
$changed = true;
}
}
if ($changed) {
// Sort languages by key.
$config['languages'] = json_decode( json_encode( $config['languages'] ), true );
ksort($config['languages']);
$config['languages'] = json_decode( json_encode( $config['languages'] ), false );
file_put_contents(CONFIG, json_encode($config, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
}
}
function get_langfolder($lang) {
$folder = LANGPACKSFOLDER.'/'.str_replace('-', '_', $lang);
if (!is_dir($folder) || !is_file($folder.'/langconfig.php')) {
return false;
}
return $folder;
}
function get_translation_strings($langfoldername, $file, $override_folder = false) {
global $strings;
if (isset($strings[$file])) {
return $strings[$file];
}
$string = import_translation_strings($langfoldername, $file);
$string_override = $override_folder ? import_translation_strings($override_folder, $file) : false;
if ($string) {
$strings[$file] = $string;
if ($string_override) {
$strings[$file] = array_merge($strings[$file], $string_override);
}
} else if ($string_override) {
$strings[$file] = $string_override;
} else {
$strings[$file] = false;
}
return $strings[$file];
}
function import_translation_strings($langfoldername, $file) {
$path = $langfoldername.'/'.$file.'.php';
// Apply translations.
if (!file_exists($path)) {
return false;
}
$string = [];
include($path);
return $string;
}
function reset_translations_strings() {
global $strings;
$strings = [];
}
function build_lang($lang, $keys) {
$langfoldername = get_langfolder($lang);
if (!$langfoldername) {
echo "Cannot translate $lang, folder not found";
return false;
}
if (OVERRIDE_LANG_SUFIX) {
$override_langfolder = get_langfolder($lang.OVERRIDE_LANG_SUFIX);
} else {
$override_langfolder = false;
}
$total = count($keys);
$local = 0;
$langparts = explode('-', $lang, 2);
$parentname = $langparts[0] ? $langparts[0] : "";
$parent = "";
echo "Processing $lang";
// Check parent language exists.
if ($parentname != $lang && get_langfolder($parentname)) {
echo " ($parentname)";
$parent = $parentname;
}
$langFile = false;
// Not yet translated. Do not override.
if (file_exists(ASSETSPATH.$lang.'.json')) {
// Load lang files just once.
$langFile = file_get_contents(ASSETSPATH.$lang.'.json');
$langFile = (array) json_decode($langFile);
}
$translations = [];
// Add the translation to the array.
foreach ($keys as $key => $value) {
$string = get_translation_strings($langfoldername, $value->file, $override_langfolder);
// Apply translations.
if (!$string) {
if ($value->file == 'donottranslate') {
// Restore it form the json.
if ($langFile && is_array($langFile) && isset($langFile[$key])) {
$translations[$key] = $langFile[$key];
} else {
// If not present, do not count it in the total.
$total--;
}
continue;
}
if (TOTRANSLATE) {
echo "\n\t\tTo translate $value->string on $value->file";
}
continue;
}
if (!isset($string[$value->string]) || ($lang == 'en' && $value->file == 'local_moodlemobileapp')) {
// Not yet translated. Do not override.
if ($langFile && is_array($langFile) && isset($langFile[$key])) {
$translations[$key] = $langFile[$key];
if ($value->file == 'local_moodlemobileapp') {
$local++;
}
}
if (TOTRANSLATE && !isset($string[$value->string])) {
echo "\n\t\tTo translate $value->string on $value->file";
}
continue;
} else {
$text = $string[$value->string];
}
if ($value->file != 'local_moodlemobileapp') {
$text = str_replace('$a->', '$a.', $text);
$text = str_replace('{$a', '{{$a', $text);
$text = str_replace('}', '}}', $text);
// Prevent double.
$text = str_replace(array('{{{', '}}}'), array('{{', '}}'), $text);
} else {
// @TODO: Remove that line when core.cannotconnect and core.login.invalidmoodleversion are completelly changed to use $a
if (($key == 'core.cannotconnect' || $key == 'core.login.invalidmoodleversion') && strpos($text, '2.4') != false) {
$text = str_replace('2.4', '{{$a}}', $text);
}
$local++;
}
$translations[$key] = html_entity_decode($text);
}
if (!empty($parent)) {
$translations['core.parentlanguage'] = $parent;
} else if (isset($translations['core.parentlanguage'])) {
unset($translations['core.parentlanguage']);
}
// Sort and save.
ksort($translations);
file_put_contents(ASSETSPATH.$lang.'.json', str_replace('\/', '/', json_encode($translations, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)));
$success = count($translations);
$percentage = floor($success/$total * 100);
$bar = progressbar($percentage);
if (strlen($lang) <= 2 && !$parent) {
echo "\t";
}
echo "\t\t$success of $total -> $percentage% $bar ($local local)\n";
if ($lang == 'en') {
generate_local_moodlemobileapp($keys, $translations);
override_component_lang_files($keys, $translations);
}
return true;
}
function progressbar($percentage) {
$done = floor($percentage/10);
return "\t".str_repeat('=', $done) . str_repeat('-', 10-$done);
}
function detect_lang($lang, $keys) {
$langfoldername = get_langfolder($lang);
if (!$langfoldername) {
echo "Cannot translate $lang, folder not found";
return false;
}
$total = count ($keys);
$success = 0;
$local = 0;
$string = get_translation_strings($langfoldername, 'langconfig');
$parent = isset($string['parentlanguage']) ? $string['parentlanguage'] : "";
if (!isset($string['thislanguage'])) {
echo "Cannot translate $lang, translated name not found";
return false;
}
$title = $lang;
if ($parent != "" && $parent != $lang) {
$title .= " ($parent)";
}
$langname = $string['thislanguage'];
$title .= " ".$langname." -D";
// Add the translation to the array.
foreach ($keys as $key => $value) {
$string = get_translation_strings($langfoldername, $value->file);
// Apply translations.
if (!$string) {
// Do not count non translatable in the totals.
if ($value->file == 'donottranslate') {
$total--;
}
continue;
}
if (!isset($string[$value->string])) {
continue;
} else {
$text = $string[$value->string];
}
if ($value->file == 'local_moodlemobileapp') {
$local++;
}
$success++;
}
$percentage = floor($success/$total * 100);
$bar = progressbar($percentage);
echo "Checking ".$title.str_repeat("\t", 7 - floor(mb_strlen($title, 'UTF-8')/8));
echo "\t$success of $total -> $percentage% $bar ($local local)";
if (($percentage > 75 && $local > 50) || ($percentage > 50 && $local > 75)) {
echo " \t DETECTED\n";
return true;
}
echo "\n";
return false;
}
function save_key($key, $value, $path) {
$filePath = $path . '/en.json';
$file = file_get_contents($filePath);
$file = (array) json_decode($file);
$value = html_entity_decode($value);
if (!isset($file[$key]) || $file[$key] != $value) {
$file[$key] = $value;
ksort($file);
file_put_contents($filePath, str_replace('\/', '/', json_encode($file, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)));
}
}
function override_component_lang_files($keys, $translations) {
echo "Override component lang files.\n";
foreach ($translations as $key => $value) {
$path = '../src/';
$exp = explode('.', $key, 3);
$type = $exp[0];
if (count($exp) == 3) {
$component = $exp[1];
$plainid = $exp[2];
} else {
$component = 'moodle';
$plainid = $exp[1];
}
switch($type) {
case 'core':
case 'addon':
switch($component) {
case 'moodle':
$path .= 'lang';
break;
default:
$path .= $type.'/'.str_replace('_', '/', $component).'/lang';
break;
}
break;
case 'assets':
$path .= $type.'/'.$component;
break;
}
if (is_file($path.'/en.json')) {
save_key($plainid, $value, $path);
}
}
}
/**
* Generates local moodle mobile app file to update languages in AMOS.
*
* @param [array] $keys Translation keys.
* @param [array] $translations English translations.
*/
function generate_local_moodlemobileapp($keys, $translations) {
echo "Generate local_moodlemobileapp.\n";
$string = '<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details.
*
* @package local
* @subpackage moodlemobileapp
* @copyright 2014 Juan Leyva <juanleyvadelgado@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string[\'appstoredescription\'] = \'NOTE: This official Moodle Mobile app will ONLY work with Moodle sites that have been set up to allow it. Please talk to your Moodle administrator if you have any problems connecting.
If your Moodle site has been configured correctly, you can use this app to:
- browse the content of your courses, even when offline
- receive instant notifications of messages and other events
- quickly find and contact other people in your courses
- upload images, audio, videos and other files from your mobile device
- view your course grades
- and more!
Please see http://docs.moodle.org/en/Mobile_app for all the latest information.
Wed really appreciate any good reviews about the functionality so far, and your suggestions on what else you want this app to do!
The app requires the following permissions:
Record audio - For recording audio to upload to Moodle
Read and modify the contents of your SD card - Contents are downloaded to the SD Card so you can see them offline
Network access - To be able to connect with your Moodle site and check if you are connected or not to switch to offline mode
Run at startup - So you receive local notifications even when the app is running in the background
Prevent phone from sleeping - So you can receive push notifications anytime\';'."\n";
foreach ($keys as $key => $value) {
if (isset($translations[$key]) && $value->file == 'local_moodlemobileapp') {
$string .= '$string[\''.$key.'\'] = \''.str_replace("'", "\'", $translations[$key]).'\';'."\n";
}
}
$string .= '$string[\'pluginname\'] = \'Moodle Mobile language strings\';'."\n";
file_put_contents('../../moodle-local_moodlemobileapp/lang/en/local_moodlemobileapp.php', $string."\n");
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Script for converting moodle strings to json.
*/
// Check we are in CLI.
if (isset($_SERVER['REMOTE_ADDR'])) {
exit(1);
}
define('MOODLE_INTERNAL', 1);
define('LANGPACKSFOLDER', '../../moodle-langpacks');
define('ASSETSPATH', '../src/assets/lang/');
define('CONFIG', '../config/config.json');
define('OVERRIDE_LANG_SUFIX', false);
global $strings;
require_once('lang_functions.php');
$config = file_get_contents(CONFIG);
$config = (array) json_decode($config);
$config_langs = array_keys(get_object_vars($config['languages']));
// Set languages to do. If script is called using a language it will be used as unique.
if (isset($argv[1]) && !empty($argv[1])) {
$forcedetect = false;
define('TOTRANSLATE', true);
$languages = explode(',', $argv[1]);
} else {
$forcedetect = true;
define('TOTRANSLATE', false);
$languages = $config_langs;
}
$keys = get_langindex_keys();
$added_langs = build_languages($languages, $keys);
if ($forcedetect) {
$new_langs = detect_languages($languages, $keys);
if (!empty($new_langs)) {
echo "\n\n\nThe following languages are going to be added\n\n\n";
$added_langs = build_languages($new_langs, $keys, $added_langs);
}
}
add_langs_to_config($added_langs, $config);

View File

@ -0,0 +1,23 @@
#!/bin/bash
source "functions.sh"
forceLang=$1
print_title 'Getting languages'
git clone --depth 1 --no-single-branch https://git.in.moodle.com/moodle/moodle-langpacks.git $LANGPACKSFOLDER
pushd $LANGPACKSFOLDER
BRANCHES=($(git branch -r --format="%(refname:lstrip=3)" --sort="refname" | grep MOODLE_))
BRANCH=${BRANCHES[${#BRANCHES[@]}-1]}
git checkout $BRANCH
git pull
popd
print_title 'Getting local mobile langs'
git clone --depth 1 https://github.com/moodlehq/moodle-local_moodlemobileapp.git ../../moodle-local_moodlemobileapp
if [ -z $forceLang ]; then
php -f moodle_to_json.php
else
php -f moodle_to_json.php "$forceLang"
fi
print_ok 'All done!'