Refactoring language system: automatically detect language files in lang/ dir instead of hardcoded list, making it easier to add new languages. Also adding a refresh in the config mod after the language has been changed.
parent
9f613ca26e
commit
52b13ba95b
|
@ -145,11 +145,11 @@ The second part is the actual message. There are a few variables you can use in
|
||||||
|
|
||||||
#### Adding a new language
|
#### Adding a new language
|
||||||
|
|
||||||
It's not the easiest thing to add a new language to the monitor, but if you can spare a few minutes of your time
|
To add a new language, follow these steps:
|
||||||
to send in a translation, it can be added to a future release.
|
|
||||||
|
|
||||||
* Create a new file in the directory "lang" named "mylanguage.lang.php".
|
* Create a new file in the directory "lang" named "mylanguage.lang.php".
|
||||||
* Copy the contents of the file "en.lang.php" to your new file.
|
* Copy the contents of the file "en.lang.php" to your new file.
|
||||||
|
* Your new language should now be available on the config page.
|
||||||
* Translate the English stuff to your own language.
|
* Translate the English stuff to your own language.
|
||||||
* Send a copy to pep[at]neanderthal-technology.com so I can add it to the next release :)
|
* Send a copy to pep[at]neanderthal-technology.com so I can add it to the next release :)
|
||||||
* Or, send me a pull request on github.
|
* Or, send me a pull request on github.
|
||||||
|
|
|
@ -59,10 +59,27 @@ class modConfig extends modCore {
|
||||||
$config[$entry['key']] = $entry['value'];
|
$config[$entry['key']] = $entry['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate language array
|
||||||
|
$lang_keys = sm_get_langs();
|
||||||
|
$languages = array();
|
||||||
|
foreach($lang_keys as $key) {
|
||||||
|
$label = sm_get_lang('config', 'language_' . $key);
|
||||||
|
// if we don't have a proper label, just show the key..
|
||||||
|
// better something than nothing huh
|
||||||
|
if($label == null) {
|
||||||
|
$label = $key;
|
||||||
|
}
|
||||||
|
$languages[] = array(
|
||||||
|
'value' => $key,
|
||||||
|
'label' => $label,
|
||||||
|
'selected' => ($key == $config['language']) ? 'selected="selected"' : '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'languages', $languages);
|
||||||
|
|
||||||
$this->tpl->addTemplateData(
|
$this->tpl->addTemplateData(
|
||||||
$this->getTemplateId(),
|
$this->getTemplateId(),
|
||||||
array(
|
array(
|
||||||
'language_selected_' . $config['language'] => 'selected="selected"',
|
|
||||||
'email_status_checked' => ($config['email_status'] == '1') ? 'checked="checked"' : '',
|
'email_status_checked' => ($config['email_status'] == '1') ? 'checked="checked"' : '',
|
||||||
'email_from_name' => $config['email_from_name'],
|
'email_from_name' => $config['email_from_name'],
|
||||||
'email_from_email' => $config['email_from_email'],
|
'email_from_email' => $config['email_from_email'],
|
||||||
|
@ -128,6 +145,11 @@ class modConfig extends modCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->message = sm_get_lang('config', 'updated');
|
$this->message = sm_get_lang('config', 'updated');
|
||||||
|
|
||||||
|
if($clean['language'] != sm_get_conf('language')) {
|
||||||
|
header('Location: ' . $_SERVER['REQUEST_URI']);
|
||||||
|
die();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// override parent::createHTMLLabels()
|
// override parent::createHTMLLabels()
|
||||||
|
@ -141,10 +163,6 @@ class modConfig extends modCore {
|
||||||
'label_settings_log' => sm_get_lang('config', 'settings_log'),
|
'label_settings_log' => sm_get_lang('config', 'settings_log'),
|
||||||
'label_general' => sm_get_lang('config', 'general'),
|
'label_general' => sm_get_lang('config', 'general'),
|
||||||
'label_language' => sm_get_lang('config', 'language'),
|
'label_language' => sm_get_lang('config', 'language'),
|
||||||
'label_language_english' => sm_get_lang('config', 'english'),
|
|
||||||
'label_language_dutch' => sm_get_lang('config', 'dutch'),
|
|
||||||
'label_language_french' => sm_get_lang('config', 'french'),
|
|
||||||
'label_language_german' => sm_get_lang('config', 'german'),
|
|
||||||
'label_show_update' => sm_get_lang('config', 'show_update'),
|
'label_show_update' => sm_get_lang('config', 'show_update'),
|
||||||
'label_email_status' => sm_get_lang('config', 'email_status'),
|
'label_email_status' => sm_get_lang('config', 'email_status'),
|
||||||
'label_email_from_email' => sm_get_lang('config', 'email_from_email'),
|
'label_email_from_email' => sm_get_lang('config', 'email_from_email'),
|
||||||
|
|
|
@ -103,6 +103,23 @@ function sm_load_lang($lang) {
|
||||||
$GLOBALS['sm_lang'] = $sm_lang;
|
$GLOBALS['sm_lang'] = $sm_lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a list with keys of the available languages
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @see sm_load_lang()
|
||||||
|
*/
|
||||||
|
function sm_get_langs() {
|
||||||
|
$fn_ext = '.lang.php';
|
||||||
|
$lang_files = glob(dirname(__FILE__) . '/lang/*' . $fn_ext);
|
||||||
|
$langs = array();
|
||||||
|
|
||||||
|
foreach($lang_files as $file) {
|
||||||
|
$langs[] = str_replace($fn_ext, '', basename($file));
|
||||||
|
}
|
||||||
|
return $langs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a setting from the config.
|
* Get a setting from the config.
|
||||||
* The config must have been loaded first using sm_load_conf()
|
* The config must have been loaded first using sm_load_conf()
|
||||||
|
|
|
@ -82,11 +82,12 @@ $sm_lang = array(
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'general' => 'General',
|
'general' => 'General',
|
||||||
'language' => 'Sprache',
|
'language' => 'Sprache',
|
||||||
|
'language_en' => 'English',
|
||||||
|
'language_nl' => 'Dutch',
|
||||||
|
'language_fr' => 'French',
|
||||||
|
'language_de' => 'German',
|
||||||
|
'language_kr' => 'Korean',
|
||||||
'show_update' => 'Updats wöchentlich prüfen?',
|
'show_update' => 'Updats wöchentlich prüfen?',
|
||||||
'english' => 'English',
|
|
||||||
'dutch' => 'Dutch',
|
|
||||||
'french' => 'French',
|
|
||||||
'german' => 'German',
|
|
||||||
'email_status' => 'Email senden erlauben?',
|
'email_status' => 'Email senden erlauben?',
|
||||||
'email_from_email' => 'Email from address',
|
'email_from_email' => 'Email from address',
|
||||||
'email_from_name' => 'Email from name',
|
'email_from_name' => 'Email from name',
|
||||||
|
|
|
@ -82,11 +82,12 @@ $sm_lang = array(
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'general' => 'General',
|
'general' => 'General',
|
||||||
'language' => 'Language',
|
'language' => 'Language',
|
||||||
|
'language_en' => 'English',
|
||||||
|
'language_nl' => 'Dutch',
|
||||||
|
'language_fr' => 'French',
|
||||||
|
'language_de' => 'German',
|
||||||
|
'language_kr' => 'Korean',
|
||||||
'show_update' => 'Check for new updates weekly?',
|
'show_update' => 'Check for new updates weekly?',
|
||||||
'english' => 'English',
|
|
||||||
'dutch' => 'Dutch',
|
|
||||||
'french' => 'French',
|
|
||||||
'german' => 'German',
|
|
||||||
'email_status' => 'Allow sending email?',
|
'email_status' => 'Allow sending email?',
|
||||||
'email_from_email' => 'Email from address',
|
'email_from_email' => 'Email from address',
|
||||||
'email_from_name' => 'Email from name',
|
'email_from_name' => 'Email from name',
|
||||||
|
|
|
@ -82,11 +82,12 @@ $sm_lang = array(
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'general' => 'General',
|
'general' => 'General',
|
||||||
'language' => 'Langue',
|
'language' => 'Langue',
|
||||||
|
'language_en' => 'English',
|
||||||
|
'language_nl' => 'Dutch',
|
||||||
|
'language_fr' => 'Francais',
|
||||||
|
'language_de' => 'German',
|
||||||
|
'language_kr' => 'Korean',
|
||||||
'show_update' => 'Vérifier les nouvelles mis à jour hebdomadairement?',
|
'show_update' => 'Vérifier les nouvelles mis à jour hebdomadairement?',
|
||||||
'english' => 'English',
|
|
||||||
'dutch' => 'Dutch',
|
|
||||||
'french' => 'Francais',
|
|
||||||
'german' => 'German',
|
|
||||||
'email_status' => 'Autoriser l envoi de mail?',
|
'email_status' => 'Autoriser l envoi de mail?',
|
||||||
'email_from_email' => 'Expéditeur',
|
'email_from_email' => 'Expéditeur',
|
||||||
'email_from_name' => 'Nom de l expéditeur',
|
'email_from_name' => 'Nom de l expéditeur',
|
||||||
|
|
|
@ -82,11 +82,12 @@ $sm_lang = array(
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'general' => 'Algemeen',
|
'general' => 'Algemeen',
|
||||||
'language' => 'Taal',
|
'language' => 'Taal',
|
||||||
|
'language_en' => 'Engels',
|
||||||
|
'language_nl' => 'Nederlands',
|
||||||
|
'language_fr' => 'Frans',
|
||||||
|
'language_de' => 'Duits',
|
||||||
|
'language_kr' => 'Koreaans',
|
||||||
'show_update' => 'Check for new updates weekly?',
|
'show_update' => 'Check for new updates weekly?',
|
||||||
'english' => 'Engels',
|
|
||||||
'dutch' => 'Nederlands',
|
|
||||||
'french' => 'Frans',
|
|
||||||
'german' => 'Duits',
|
|
||||||
'email_status' => 'Sta email berichten toe?',
|
'email_status' => 'Sta email berichten toe?',
|
||||||
'email_from_email' => 'Email van adres',
|
'email_from_email' => 'Email van adres',
|
||||||
'email_from_name' => 'Email van naam',
|
'email_from_name' => 'Email van naam',
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
<label class="control-label" for="language">{label_language}</label>
|
<label class="control-label" for="language">{label_language}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<select name="language">
|
<select name="language">
|
||||||
<option value="en" {language_selected_en}>{label_language_english}</option>
|
<!--%tpl_repeat_languages-->
|
||||||
<option value="nl" {language_selected_nl}>{label_language_dutch}</option>
|
<option value="{value}" {selected}>{label}</option>
|
||||||
<option value="fr" {language_selected_fr}>{label_language_french}</option>
|
<!--%%tpl_repeat_languages-->
|
||||||
<option value="de" {language_selected_de}>{label_language_german}</option>
|
{languages}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue