2007-09-16 18:03:32 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* An extension to dropdown field, pre-configured to list languages.
|
|
|
|
* The languages already used in the site will be on top.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
2007-09-16 18:03:32 +02:00
|
|
|
*/
|
|
|
|
class LanguageDropdownField extends GroupedDropdownField {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new LanguageDropdownField
|
|
|
|
* @param string $name
|
|
|
|
* @param string $title
|
|
|
|
* @param array $dontInclude list of languages that won't be included
|
|
|
|
* @param string $translatingClass Name of the class with translated instances where to look for used languages
|
2007-09-27 22:59:46 +02:00
|
|
|
* @param string $list Indicates the source language list. Can be either Common-English, Common-Native Locale
|
2007-09-16 18:03:32 +02:00
|
|
|
*/
|
|
|
|
function __construct($name, $title, $dontInclude = array(), $translatingClass = 'SiteTree', $list = 'Common-English' ) {
|
|
|
|
$usedlangs = array_diff(
|
2007-10-24 06:27:54 +02:00
|
|
|
i18n::get_existing_content_languages($translatingClass),
|
|
|
|
$dontInclude
|
|
|
|
);
|
2007-09-16 18:03:32 +02:00
|
|
|
// we accept in dontInclude both language codes and names, so another diff is required
|
2007-10-24 06:27:54 +02:00
|
|
|
$usedlangs = array_diff(
|
|
|
|
$usedlangs,
|
|
|
|
array_flip($dontInclude)
|
|
|
|
);
|
2007-09-27 22:59:46 +02:00
|
|
|
|
2007-09-16 18:03:32 +02:00
|
|
|
if (isset($usedlangs[Translatable::default_lang()])) unset($usedlangs[Translatable::default_lang()]);
|
|
|
|
|
|
|
|
if ('Common-English' == $list) $languageList = i18n::get_common_languages();
|
|
|
|
else if ('Common-Native' == $list) $languageList = i18n::get_common_languages(true);
|
|
|
|
else $languageList = i18n::get_locale_list();
|
|
|
|
|
|
|
|
$alllangs = array_diff(
|
|
|
|
$languageList,
|
|
|
|
(array)$usedlangs,
|
|
|
|
$dontInclude
|
|
|
|
);
|
|
|
|
$alllangs = array_flip(array_diff(
|
|
|
|
array_flip($alllangs),
|
|
|
|
$dontInclude
|
|
|
|
));
|
|
|
|
if (isset($alllangs[Translatable::default_lang()])) unset($alllangs[Translatable::default_lang()]);
|
|
|
|
|
2007-09-25 23:57:54 +02:00
|
|
|
asort($alllangs);
|
2007-09-16 18:03:32 +02:00
|
|
|
if (count($usedlangs)) {
|
2007-09-25 23:57:54 +02:00
|
|
|
asort($usedlangs);
|
2007-10-25 04:47:45 +02:00
|
|
|
$labelAvail = _t('Form.LANGAVAIL', "Available languages");
|
|
|
|
$labelOther = _t('Form.LANGAOTHER', "Other languages");
|
2007-09-16 18:03:32 +02:00
|
|
|
parent::__construct($name, $title, array(
|
2007-10-25 04:47:45 +02:00
|
|
|
$labelAvail => $usedlangs,
|
|
|
|
$labelOther => $alllangs
|
2007-09-16 18:03:32 +02:00
|
|
|
),
|
|
|
|
reset($usedlangs)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent::__construct($name, $title, $alllangs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|