first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
/**
* @file
* Variable Realm controller.
*/
/**
* Controller for Language realms.
*/
class I18nVariableLanguageRealm extends VariableRealmDefaultController {
/**
* Implementation of VariableRealmControllerInterface::getAvailableVariables().
*/
public function getAvailableVariables() {
$translatable = array();
$conf = variable_get('i18n_variables', array());
foreach (variable_get_info() as $name => $variable) {
if (!empty($variable['localize']) || in_array($name, $conf)) {
$translatable[] = $name;
}
}
return $translatable;
}
/**
* Implementation of VariableRealmControllerInterface::getDefaultKey().
*/
public function getDefaultKey() {
// The default key will match the default language.
return language_default('language');
}
/**
* Implementation of VariableRealmControllerInterface::getRequestKey().
*/
public function getRequestKey() {
return i18n_variable_language()->language;
}
/**
* Implementation of VariableRealmControllerInterface::getAllKeys().
*/
public function getAllKeys() {
return locale_language_list('name', TRUE);
}
}

View File

@@ -0,0 +1,18 @@
name = Variable translation
description = Multilingual variables that switch language depending on page language.
dependencies[] = i18n
dependencies[] = variable_store (7.x-2.x)
dependencies[] = variable_realm (7.x-2.x)
package = Multilingual - Internationalization
core = 7.x
configure = admin/config/regional/i18n/variable
files[] = i18n_variable.class.inc
files[] = i18n_variable.test
; Information added by drupal.org packaging script on 2013-01-13
version = "7.x-1.8"
core = "7.x"
project = "i18n"
datestamp = "1358075001"

View File

@@ -0,0 +1,83 @@
<?php
/**
* @file
* Installation file for Internationalization (i18n) module.
*/
/**
* Implements hook_install().
*/
function i18n_variable_install() {
// Set module weight for it to run before most modules, but after variable_realm
db_query("UPDATE {system} SET weight = -900 WHERE name = 'i18n_variable' AND type = 'module'");
// Update from d6, module changed name
if (variable_get('i18n_drupal6_update')) {
i18n_variable_update_7000();
i18n_variable_update_7001();
i18n_variable_update_7002();
}
// Set some minimum variables to be translated.
variable_set('variable_realm_list_language', array('site_name', 'site_slogan'));
}
/**
* Implements hook_install().
*/
function i18n_variable_uninstall() {
if (drupal_load('module', 'variable_store')) {
// Delete all our variables from store.
variable_store_delete_all('language', NULL);
}
}
/**
* Update multilingual variables variable name
*/
function i18n_variable_update_7000() {
variable_set('i18n_variable_list', variable_get('i18n_variables', array()));
variable_set('i18n_variable_conf', variable_get('i18n_variables', array()));
variable_del('i18n_variables');
}
/**
* Move variables from old storage to new table
*/
function i18n_variable_update_7001() {
drupal_load('module', 'variable_store');
foreach (db_select('i18n_variable', 'v')->fields('v')->execute()->fetchAll() as $variable) {
variable_store_set('language', $variable->language, $variable->name, unserialize($variable->value));
}
}
/**
* Drop i18n_variable table if exists
*/
function i18n_variable_update_7002() {
if (db_table_exists('i18n_variable')) {
db_drop_table('i18n_variable');
}
}
/**
* Update list of realm variables.
*/
function i18n_variable_update_7003() {
drupal_load('module', 'variable_store');
$variable_list = variable_get('i18n_variable_conf', array());
variable_set('variable_realm_list_language', $variable_list);
// Delete old variables from store that are not in the list.
$old_variables = array_diff(variable_store_list_all('language'), variable_children($variable_list));
foreach ($old_variables as $name) {
variable_store_delete_all('language', NULL, $name);
}
}
/**
* Delete obsoleted variable realm variables.
*/
function i18n_variable_update_7004() {
variable_del('i18n_variable_conf');
variable_del('i18n_variable_list');
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* @file
* Internationalization (i18n) package. Multilingual variables API.
*/
/**
* The type of language used for variables.
*/
define('I18N_VARIABLE_LANGUAGE_TYPE', 'i18n_language_variable');
/**
* Implements hook_language_init()
*/
function i18n_variable_language_init() {
if (drupal_multilingual()) {
module_invoke('variable_realm', 'initialize', 'language');
}
}
/**
* Implements hook_variable_realm_info().
*/
function i18n_variable_variable_realm_info() {
$realm['language'] = array(
'title' => t('Language'),
'weight' => 100,
'controller class' => 'I18nVariableLanguageRealm',
'store class' => 'VariableStoreRealmStore',
// Variables for this realm can be selected from a list.
'select' => TRUE,
'select path' => 'admin/config/regional/i18n/variable',
// Name for variables that belong to this realm: 'multilingual' variable/s
'variable name' => t('multilingual'),
'variable class' => 'i18n-variable',
// Automatically handle these variables in system settings forms.
'form settings' => TRUE,
'form switcher' => TRUE,
);
return $realm;
}
/**
* Implements hook_menu()
*/
function i18n_variable_menu() {
$items['admin/config/regional/i18n/variable'] = array(
'title' => 'Variables',
'description' => 'Configure multilingual variables.',
'page callback' => 'drupal_get_form',
'page arguments' => array('variable_realm_select_variables_form', 'language'),
'access arguments' => array('administer site configuration'),
'file' => 'variable_realm.form.inc',
'file path' => drupal_get_path('module', 'variable_realm'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Get variables language, make sure it is initialized
*/
function i18n_variable_language() {
// If we've got a variables language, it will be that one
if (!isset($GLOBALS[I18N_VARIABLE_LANGUAGE_TYPE])) {
$GLOBALS[I18N_VARIABLE_LANGUAGE_TYPE] = i18n_language_interface();
}
return $GLOBALS[I18N_VARIABLE_LANGUAGE_TYPE];
}
/**
* Get original value for global variable/s
*/
function i18n_variable_global($name = NULL, $default = NULL) {
return variable_realm_global_get($name, $default);
}
/**
* Get list of multilingual variables or check whether a variable is multilingual
*/
function i18n_variable_list($name = NULL) {
$variables = &drupal_static(__FUNCTION__);
if (!isset($variables)) {
$variables = variable_children(variable_get('variable_realm_list_language', array()));
}
return $name ? in_array($name, $variables) : $variables;
}
/**
* Load language variables into array.
*
* Pull variables from the store but filter out the ones that are not multilingual.
*/
function i18n_variable_load($langcode) {
$variables = array();
foreach (variable_store('language', $langcode) as $name => $value) {
if (i18n_variable_list($name)) {
$variables[$name] = $value;
}
}
return $variables;
}
/**
* Set a persistent language dependent variable.
*
* @param $name
* The name of the variable to set.
* @param $value
* The value to set. This can be any PHP data type; these functions take care
* of serialization as necessary.
* @param $langcode
* Language code.
*/
function i18n_variable_set($name, $value, $langcode) {
variable_realm_set('language', $langcode, $name, $value);
}
/**
* Get single multilingual variable
*/
function i18n_variable_get($name, $langcode, $default = NULL) {
return variable_realm_get('language', $langcode, $name, $default);
}
/**
* Unset a persistent multilingual variable.
*
* @param $name
* The name of the variable to undefine.
* @param $langcode
* Language code.
*/
function i18n_variable_del($name, $langcode) {
variable_realm_del('language', $langcode, $name);
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* @file
* Test case for multilingual variables
*/
class i18nVariableTestCase extends Drupali18nTestCase {
public static function getInfo() {
return array(
'name' => 'Variable translation',
'group' => 'Internationalization',
'description' => 'Variable translation functions'
);
}
function setUp() {
parent::setUp('i18n_variable', 'translation');
parent::setUpLanguages(array('administer site configuration'));
}
/**
* Set up translation for content type (page)
*/
function setUpContentTranslation($settings = array()) {
$this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content'));
$this->drupalLogin($this->admin_user);
// Set "Basic page" content type to use multilingual support with
// translation.
$this->drupalGet('admin/structure/types/manage/page');
$edit = array();
$edit['language_content_type'] = 2;
// Mark status and promoted
$edit['node_options[status]'] = 1;
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
// Enable the language switcher block.
$language_type = LANGUAGE_TYPE_INTERFACE;
$edit = array("blocks[locale_$language_type][region]" => 'sidebar_first');
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
}
function testVariableLocalize() {
$this->setUpContentTranslation();
// Create 2 nodes in different languages.
$first_title = $this->randomName(10);
$first_body = $this->randomString(50);
$first_node = $this->createNode('page', $first_title, $first_body, $this->default_language);
$secondary_title = $this->randomName(10);
$secondary_body = $this->randomString(50);
$secondary_node = $this->createNode('page', $secondary_title, $secondary_body, $this->secondary_language);
$this->drupalGet('<front>', array('language' => i18n_language_object($this->default_language)));
$this->assertText(t('No front page content has been created yet.'));
$this->drupalGet('<front>', array('language' => i18n_language_object($this->secondary_language)));
$this->assertText(t('No front page content has been created yet.'));
$edit = array(
'variables[site_name]' => 1,
'variables[site_frontpage]' => 1,
);
$this->drupalPost('admin/config/regional/i18n/variable', $edit, t('Save configuration'));
$edit_first = array(
'site_frontpage' => 'node/' . $first_node->nid,
'site_name' => $this->randomName(10),
);
$this->drupalPost('admin/config/system/site-information', $edit_first, t('Save configuration'), array('language' => i18n_language_object($this->default_language)));
$edit_secondary = array(
'site_frontpage' => 'node/' . $secondary_node->nid,
'site_name' => $this->randomName(10),
);
$this->drupalPost('admin/config/system/site-information', $edit_secondary, t('Save configuration'), array('language' => i18n_language_object($this->secondary_language)));
$this->drupalGet('<front>', array('language' => i18n_language_object($this->default_language)));
$this->assertText($edit_first['site_name']);
$this->assertNoText(t('No front page content has been created yet.'));
$this->assertText($first_title);
$this->drupalGet('<front>', array('language' => i18n_language_object($this->secondary_language)));
$this->assertText($edit_secondary['site_name']);
$this->assertNoText(t('No front page content has been created yet.'));
$this->assertText($secondary_title);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Variable information
*/
/**
* Implements hook_variable_info().
*/
function i18n_variable_variable_info($options = array()) {
$variables['i18n_variable_conf'] = array(
'title' => t('Multilingual variables, main variable names.', array(), $options),
'type' => 'array',
'group' => 'i18n',
);
$variables['i18n_variable_list'] = array(
'title' => t('Multilingual variables, real variable names.', array(), $options),
'type' => 'array',
'group' => 'i18n',
);
return $variables;
}