Skip to content

Commit

Permalink
Merge pull request backdrop-contrib#4 from laryn/1.x
Browse files Browse the repository at this point in the history
README/LICENSE/Drupal issue
Attempts to merge work from @herbdool
  • Loading branch information
docwilmot authored Nov 9, 2016
2 parents 2713bef + ca9fbc9 commit f0c5c7e
Show file tree
Hide file tree
Showing 22 changed files with 687 additions and 277 deletions.
339 changes: 339 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Internationalization (i18n)

This is a collection of modules to extend Backdrop core multilingual
capabilities and be able to build full-featured multilingual sites. This
module makes possible:

- Taxonomy translation (both, per language terms and translatable terms)
- Multilingual variables
- Multilingual blocks (control visibility per language and translate title and content)
- Language selection (when you switch the site language you'll see only the content for that language)

Documentation will be kept in the [wiki](https://github.com/backdrop-contrib/i18n/wiki).

##Installation

- Install this module using the official
[Backdrop CMS instructions](https://backdropcms.org/guide/modules)


##Issues

Bugs and Feature requests should be reported in the
[Issue Queue](https://github.com/backdrop-contrib/i18n/issues)

##Current Maintainers

- [docwilmot](https://github.com/docwilmot)
- Help wanted

##Credits

- Port to Backdrop CMS was begun by [docwilmot](https://github.com/docwilmot) and is still in process.
- Maintainer for the Drupal module: Jose A. Reyero.

##License

This project is GPL v2 software. See the [LICENSE.txt](https://github.com/backdrop-contrib/i18n/blob/1.x-1.x/LICENSE.txt)
file in this directory for complete text.
27 changes: 0 additions & 27 deletions README.txt

This file was deleted.

26 changes: 26 additions & 0 deletions i18n.install
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ function i18n_install() {
db_query("UPDATE {system} SET weight = 10 WHERE name = 'i18n' AND type = 'module'");
}

/**
* Implements hook_uninstall().
*/
function i18n_uninstall() {
}

/**
* Add fields to the schema if they don't exist.
*
Expand Down Expand Up @@ -42,3 +48,23 @@ function i18n_install_create_fields($table, $fields, $force_rebuild_schema = FAL
}
}
}

/**
* Implements hook_update_last_removed().
*/
function i18n_update_last_removed() {
return 7001;
}

/**
* Move book settings from variables to config.
*/
function i18n_update_1000() {
// Migrate variables to config.
//$config = config('i18n.settings');
//$config->set('book_allowed_types', update_variable_get('book_allowed_types', array('book')));
//$config->save();

// Delete variables.
//update_variable_del('book_allowed_types');
}
37 changes: 24 additions & 13 deletions i18n.module
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ define('I18N_MODE_MULTIPLE', I18N_MODE_LOCALIZE | I18N_MODE_TRANSLATE);
*/
define('I18N_LANGUAGE_TYPE_CONTEXT', 'i18n_language_context');

/**
* Implements hook_autoload_info()
*/
function i18n_autoload_info() {
return array(
'i18n_object_wrapper' => 'i18n_object.inc'
);
}

/**
* Implements hook_boot().
*/
Expand All @@ -60,28 +69,30 @@ function i18n_config_info() {
/**
* Implements hook_autoload_info().
*/
/*
function i18n_autoload_info() {
return array(
'i18n_block_object' => 'i18n_block/i18n_block.inc',
'i18n_field_base' => 'i18n_field/i18n_field.inc',
'i18n_field' => 'i18n_field/i18n_field.inc',
'i18n_field_instance' => 'i18n_field/i18n_field.inc',
'i18n_menu_link_translation_set' => 'i18n_menu\i18n_menu.inc',
'i18n_menu_link' => 'i18n_menu\i18n_menu.inc',
'i18n_menu_link_translation_set' => 'i18n_menu/i18n_menu.inc',
'i18n_menu_link' => 'i18n_menu/i18n_menu.inc',
'i18n_object_wrapper' => 'i18n_object.inc',
'i18n_path_translation_set' => 'i18n_path\i18n_path.inc',
'i18n_path_object' => 'i18n_path\i18n_path.inc',
'i18n_string_object' => 'i18n_string\i18n_string.inc',
'i18n_string_textgroup_default' => 'i18n_string\i18n_string.inc',
'i18n_string_object_wrapper' => 'i18n_string\i18n_string.inc',
'i18n_taxonomy_translation_set' => 'i18n_taxonomy\i18n_taxonomy.inc',
'i18n_taxonomy_term extends' => 'i18n_taxonomy\i18n_taxonomy.inc',
'i18n_string_textgroup_cached' => 'i18n_string\i18n_string.inc',
'i18n_translation_set' => 'i18n_translation\i18n_translation.inc',
'I18nTranslationSetController' => 'i18n_translation\i18n_translation.module',
'I18nVariableLanguageRealm' => 'i18n_variable\i18n_variable.module',
'i18n_path_translation_set' => 'i18n_path/i18n_path.inc',
'i18n_path_object' => 'i18n_path/i18n_path.inc',
'i18n_string_object' => 'i18n_string/i18n_string.inc',
'i18n_string_textgroup_default' => 'i18n_string/i18n_string.inc',
'i18n_string_object_wrapper' => 'i18n_string/i18n_string.inc',
'i18n_taxonomy_translation_set' => 'i18n_taxonomy/i18n_taxonomy.inc',
'i18n_taxonomy_term extends' => 'i18n_taxonomy/i18n_taxonomy.inc',
'i18n_string_textgroup_cached' => 'i18n_string/i18n_string.inc',
'i18n_translation_set' => 'i18n_translation/i18n_translation.inc',
'I18nTranslationSetController' => 'i18n_translation/i18n_translation.module',
'I18nVariableLanguageRealm' => 'i18n_variable/i18n_variable.module',
);
}
*/

/**
* Implements hook_hook_info().
Expand Down
20 changes: 20 additions & 0 deletions i18n_menu/i18n_menu.module
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ function i18n_menu_menu_alter(&$items) {
$items['admin/structure/menu/item/%menu_link'] = $items['admin/structure/menu/item/%menu_link/edit'];
$items['admin/structure/menu/item/%menu_link']['type'] = MENU_CALLBACK;
$items['admin/structure/menu/item/%menu_link/edit']['type'] = MENU_DEFAULT_LOCAL_TASK;
$items['admin/structure/menu/manage/%menu']['title callback'] = 'i18n_menu_menu_overview_title';
}

/**
* Preprocess theme_menu_admin_overview to translate menu name and description
*
* @param $variables
*/
function i18n_menu_preprocess_menu_admin_overview(&$variables) {
$variables['title'] = i18n_string(array('menu', 'menu', $variables['name'], 'title'), $variables['title']);
$variables['description'] = i18n_string(array('menu', 'menu', $variables['name'], 'description'), $variables['description']);
}

/**
* Title callback for the menu overview page and links.
*/
function i18n_menu_menu_overview_title($menu) {
return i18n_string(array('menu', 'menu', $menu['menu_name'], 'title'), $menu['title']);
}

/**
Expand Down Expand Up @@ -747,13 +765,15 @@ function i18n_menu_form_menu_edit_item_alter(&$form, &$form_state) {
function i18n_menu_form_menu_overview_form_alter(&$form, &$form_state) {
foreach (element_children($form) as $element) {
if (substr($element, 0, 5) == 'mlid:') {
$item = $form[$element]["#item"];
$mlid = $form[$element]['#item']['mlid'];
if (i18n_get_object('menu', $mlid)->get_translate_access()) {
$form[$element]['operations']['translate'] = array(
'#type' => 'link',
'#title' => t('translate'),
'#href' => "admin/structure/menu/item/{$mlid}/translate",
);
$form[$element]['title']['#markup'] = l(_i18n_menu_link_title($item), $item['href'], $item['localized_options']);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions i18n_string/i18n_string.info
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ backdrop = 1.x
type = module

files[] = i18n_string.admin.inc
files[] = i18n_string.inc
files[] = i18n_string.test
;files[] = i18n_string.inc
;files[] = i18n_string.test
configure = admin/config/regional/i18n/strings
81 changes: 22 additions & 59 deletions i18n_string/i18n_string.install
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ function i18n_string_schema_alter(&$schema) {
'not null' => TRUE,
'default' => 0,
);

// Locale in core dropped textgroup column for locales_source
// It assumes that i18n has migrated it BEFORE dropping.
$schema['locales_source']['fields']['textgroup'] = array(
'type' => 'varchar',
'length' => 255,
Expand Down Expand Up @@ -213,69 +216,29 @@ function i18n_string_install_update_context($oldname, $newname) {
}
}

/**
* Populate fields from old locale table (textgroup, location) and drop indexes from locales_source
*/
function i18n_string_update_7000() {
// @todo Update from d6
variable_del('i18nstrings_allowed_textgroups');
// If we've got old table from D6, move data to new one
if (db_table_exists('i18n_strings')) {
// First of all clean up strings that don't have a locale source, see http://backdrop.org/node/1186692
db_query("DELETE FROM {i18n_strings} WHERE lid NOT IN (SELECT lid FROM {locales_source})");
db_query("INSERT INTO {i18n_string}(lid, objectid, type, property, objectindex, format) SELECT lid, objectid, type, property, objectindex, format FROM {i18n_strings}");
// Update and populate textgroup field
db_query("UPDATE {i18n_string} s SET s.textgroup = (SELECT l.textgroup FROM {locales_source} l WHERE l.lid = s.lid)");
// Populate context field. We could use CONCAT_WS but I guess this is more standard.
db_query("UPDATE {i18n_string} SET context = CONCAT(type, ':', objectid, ':', property)");
db_query("UPDATE {locales_source} s INNER JOIN {i18n_string} i ON s.lid = i.lid SET s.context = i.context");
}
}

/**
* Drop obsoleted i18n_strings table if exists
* Implements hook_update_last_removed().
*/
function i18n_string_update_7001() {
if (db_table_exists('i18n_strings')) {
db_drop_table('i18n_strings');
}
function i18n_string_update_last_removed() {
return 7002;
}

/**
* Create new index in {locales_source}, performance improvement in sites with i18n.
*/
function i18n_string_update_7002() {
if (!db_index_exists('locales_source', 'textgroup_context')) {
db_add_index('locales_source', 'textgroup_context', array('textgroup', array('context', 50)));
}
}


/**
* Notes for update script
*/
// Added fields: context, textgroup
//
// Drop all indexes from locales_source
// Update format field
// Update string names: profile, cck => field
// Update string names:

/**
* Old strings to update. All these will be handled by i18n_field module
*
* 'cck:field:'. $content_type .'-'. $field_name .':widget_label'
* --> 'field:$field_name:$bundle:label' (though not used atm)
* 'cck:field:'. $content_type .'-'. $field_name .':widget_description'
* --> 'field:$field_name:$bundle:description'
* 'cck:fieldgroup:'. $content_type .'-'. $group_name .':display_description'
* 'cck:fieldgroup:'. $content_type .'-'. $group_name .':form_description', $group['settings']['form']['description']);
*
* Profile:
* profile:field:$field_name:title|explanation|options
* "profile:category", $field->category
*
* Node type
* nodetype:type:[type]:[property] -> node:type:[type]:[property]
* Property names: title -> title_label
* Move book settings from variables to config.
*/
function i18n_string_update_1000() {
// Migrate variables to config.
$config = config('i18n_string.settings');
$config->set('debug', update_variable_get('i18n_string_debug', FALSE));
$config->set('i18n_loaded_translations', update_variable_get('i18n_loaded_translations',array()));
$config->set('i18n_string_allowed_formats', update_variable_get('i18n_string_allowed_formats', array(filter_fallback_format())));
//i18n_string_debug_' . $textgroup -- update all without knowing how many?

$config->save();

// Delete variables.
update_variable_del('i18n_string_debug');
update_variable_del('i18n_loaded_translations');
update_variable_del('i18n_string_allowed_formats');
}
34 changes: 30 additions & 4 deletions i18n_string/i18n_string.module
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ define('I18N_STRING_FILTER_XSS', 'FILTER_XSS');
*/
define('I18N_STRING_FILTER_XSS_ADMIN', 'FILTER_XSS_ADMIN');

/**
* Implements hook_config_info().
*/
function i18n_string_config_info() {
$prefixes['i18n_string.settings'] = array(
'label' => t('String Translation settings'),
'group' => t('Configuration'),
);
return $prefixes;
}

/**
* Implements hook_autoload_info()
*/
function i18n_string_autoload_info() {
return array(
'i18n_string_object' => 'i18n_string.inc',
'i18n_string_textgroup_default' => 'i18n_string.inc',
'i18n_string_object_wrapper' => 'i18n_string.inc',
'i18n_string_textgroup_cached' => 'i18n_string.inc',
);
};

/**
* Implements hook_help().
*/
Expand Down Expand Up @@ -118,6 +141,7 @@ function i18n_string_menu() {
'file' => 'i18n_string.admin.inc',
'access arguments' => array('translate interface'),
);
//TODO: remove this comment once working; It's here to note that the array below is slightly different in docwilmot and herbdool's versions. Not sure which is accurate yet.
$items['admin/config/regional/i18n/strings'] = array(
'title' => 'Strings',
'description' => 'Options for user defined strings.',
Expand Down Expand Up @@ -282,7 +306,8 @@ function i18n_string_translate_langcode($langcode = NULL) {
$translate = &backdrop_static(__FUNCTION__);
$langcode = isset($langcode) ? $langcode : i18n_langcode();
if (!isset($translate[$langcode])) {
$translate[$langcode] = config_get('i18n.settings', 'i18n_string_translate_langcode_' . $langcode);
$i18n_string_translate_langcode = config_get('i18n_string.settings', 'i18n_string_translate_langcode_' . $langcode);
$translate[$langcode] = i18n_string_source_language() != $langcode ? i18n_string_source_language() : $i18n_string_translate_langcode;
}
return $translate[$langcode];
}
Expand Down Expand Up @@ -355,7 +380,8 @@ function i18n_string_allowed_format($format_id = NULL) {
}
else {
// Check the format still exists an it is in the allowed formats list.
return filter_format_load($format_id) && in_array($format_id, config_get('i18n.settings', 'i18n_string_allowed_formats'), TRUE);
$allowed_formats = config_get('i18n_string.settings', 'allowed_formats');
return filter_format_load($format_id) && in_array($format_id, $allowed_formats ? $allowed_formats : array(filter_fallback_format()), TRUE);
}
}

Expand Down Expand Up @@ -455,7 +481,7 @@ function i18n_string_load_multiple($conditions) {
$query->condition($alias . '.' . $field, $value);
}
// this patch is a workaround for core file bug in file
// include/database/prefetch.inc (see: http://backdrop.org/node/1567216)
// include/database/prefetch.inc (see: http://drupal.org/node/1567216)
// return $query->execute()->fetchAll(PDO::FETCH_CLASS, 'i18n_string_object');
$stmt = $query->execute();
$stmt->setFetchMode(PDO::FETCH_CLASS, 'i18n_string_object');
Expand Down Expand Up @@ -689,7 +715,7 @@ function i18n_string_plain($name, $default, $options = array()) {
* Get source language code for translations
*/
function i18n_string_source_language() {
return config_get('i18n.settings', 'i18n_string_source_language');
return config_get('i18n_string.settings', 'i18n_string_source_language');
}

/**
Expand Down
Loading

0 comments on commit f0c5c7e

Please sign in to comment.