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
|
2009-03-20 09:38:57 +01:00
|
|
|
* @param string $list Indicates the source language list. Can be either Common-English, Common-Native, Locale-English, Locale-Native
|
2007-09-16 18:03:32 +02:00
|
|
|
*/
|
|
|
|
function __construct($name, $title, $dontInclude = array(), $translatingClass = 'SiteTree', $list = 'Common-English' ) {
|
|
|
|
$usedlangs = array_diff(
|
2009-01-10 12:35:50 +01:00
|
|
|
Translatable::get_existing_content_languages($translatingClass),
|
2007-10-24 06:27:54 +02:00
|
|
|
$dontInclude
|
|
|
|
);
|
2009-01-19 00:07:51 +01:00
|
|
|
|
2007-09-16 18:03:32 +02:00
|
|
|
// we accept in dontInclude both language codes and names, so another diff is required
|
2009-01-19 00:07:51 +01:00
|
|
|
$usedlangs = array_diff_key(
|
2007-10-24 06:27:54 +02:00
|
|
|
$usedlangs,
|
|
|
|
array_flip($dontInclude)
|
|
|
|
);
|
2007-09-27 22:59:46 +02:00
|
|
|
|
2009-03-20 09:38:57 +01:00
|
|
|
//if (isset($usedlangs[Translatable::default_locale()])) unset($usedlangs[Translatable::default_locale()]);
|
2007-09-16 18:03:32 +02:00
|
|
|
|
|
|
|
if ('Common-English' == $list) $languageList = i18n::get_common_languages();
|
|
|
|
else if ('Common-Native' == $list) $languageList = i18n::get_common_languages(true);
|
2009-03-20 09:38:57 +01:00
|
|
|
else if ('Locale-English' == $list) $languageList = i18n::get_common_locales();
|
|
|
|
else if ('Locale-Native' == $list) $languageList = i18n::get_common_locales(true);
|
2007-09-16 18:03:32 +02:00
|
|
|
else $languageList = i18n::get_locale_list();
|
|
|
|
|
|
|
|
$alllangs = array_diff(
|
2009-03-20 09:38:57 +01:00
|
|
|
$languageList,
|
|
|
|
(array)$usedlangs,
|
|
|
|
$dontInclude
|
|
|
|
);
|
2007-09-16 18:03:32 +02:00
|
|
|
$alllangs = array_flip(array_diff(
|
2009-03-20 09:38:57 +01:00
|
|
|
array_flip($alllangs),
|
|
|
|
$dontInclude
|
|
|
|
));
|
|
|
|
if (isset($alllangs[Translatable::default_locale()])) unset($alllangs[Translatable::default_locale()]);
|
2007-09-16 18:03:32 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|