Commit 1831e1b6 authored by Dries's avatar Dries

- New locale module thanks to Gerhard, Goba, Marco, Kristjan and others.

  The new locale module provides every functionality on the web interface, so you don't need to edit the configuration files or add columns, when you add a new language. This module is an integration of the old locale and localegettext modules, plus a bunch of logic to parse Gettext Portable Object files (opposed to Machine Object files, as supported by localegettext).

  Note: I made some minor changes to the context-sensitive help texts and to some of the status messages.
parent 8517e17e
......@@ -255,24 +255,46 @@ CREATE TABLE history (
) TYPE=MyISAM;
--
-- Table structure for table 'locales'
-- Table structure for table 'locales_meta'
--
CREATE TABLE locales (
lid int(10) NOT NULL auto_increment,
CREATE TABLE locales_meta (
locale varchar(12) NOT NULL default '',
name varchar(64) NOT NULL default '',
enabled int(2) NOT NULL default '0',
isdefault int(2) NOT NULL default '0',
plurals int(1) NOT NULL default '0',
formula varchar(128) NOT NULL default '',
PRIMARY KEY (locale)
) TYPE=MyISAM;
--
-- Table structure for table 'locales_source'
--
CREATE TABLE locales_source (
lid int(11) NOT NULL auto_increment,
location varchar(128) NOT NULL default '',
string blob NOT NULL,
da blob NOT NULL,
fi blob NOT NULL,
fr blob NOT NULL,
en blob NOT NULL,
es blob NOT NULL,
nl blob NOT NULL,
no blob NOT NULL,
sw blob NOT NULL,
source blob NOT NULL,
PRIMARY KEY (lid)
) TYPE=MyISAM;
--
-- Table structure for table 'locales_target'
--
CREATE TABLE locales_target (
lid int(11) NOT NULL default '0',
translation blob NOT NULL,
locale varchar(12) NOT NULL default '',
plid int(11) NOT NULL default '0',
plural int(1) NOT NULL default '0',
KEY lid (lid),
KEY lang (locale),
KEY plid (plid),
KEY plural (plural)
) TYPE=MyISAM;
--
-- Table structure for table 'menu'
--
......@@ -620,7 +642,7 @@ CREATE TABLE users (
changed int(11) NOT NULL default '0',
status tinyint(4) NOT NULL default '0',
timezone varchar(8) default NULL,
language char(2) NOT NULL default '',
language varchar(12) NOT NULL default '',
picture varchar(255) NOT NULL DEFAULT '',
init varchar(64) default '',
data longtext,
......@@ -723,3 +745,5 @@ INSERT INTO filters VALUES (1,'filter',3,1);
INSERT INTO filters VALUES (2,'filter',1,0);
INSERT INTO filters VALUES (3,'filter',3,0);
INSERT INTO variable (name,value) VALUES ('filter_html_1','i:1;');
INSERT INTO locales_meta (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1');
......@@ -242,24 +242,48 @@ CREATE TABLE history (
);
--
-- Table structure for locales
-- Table structure for locales_meta
--
CREATE TABLE locales (
lid SERIAL,
CREATE TABLE locales_meta (
locale varchar(12) NOT NULL default '',
name varchar(64) NOT NULL default '',
enabled int4 NOT NULL default '0',
isdefault int4 NOT NULL default '0',
plurals int4 NOT NULL default '0',
formula varchar(128) NOT NULL default '',
PRIMARY KEY (locale)
);
--
-- Table structure for locales_source
--
CREATE sequence locales_source_lid_seq;
CREATE TABLE locales_source (
lid integer DEFAULT nextval('locales_source_lid_seq'::text) NOT NULL,
location varchar(128) NOT NULL default '',
string text NOT NULL default '',
da text NOT NULL default '',
fi text NOT NULL default '',
fr text NOT NULL default '',
en text NOT NULL default '',
es text NOT NULL default '',
nl text NOT NULL default '',
no text NOT NULL default '',
sw text NOT NULL default '',
source text NOT NULL,
PRIMARY KEY (lid)
);
--
-- Table structure for locales_target
--
CREATE TABLE locales_target (
lid int4 NOT NULL default '0',
translation text NOT NULL,
locale varchar(12) NOT NULL default '',
plid int4 NOT NULL default '0',
plural int4 NOT NULL default '0',
UNIQUE (lid),
UNIQUE (locale),
UNIQUE (plid),
UNIQUE (plural)
);
--
-- Table structure for table 'menu'
--
......@@ -601,7 +625,7 @@ CREATE TABLE users (
changed integer NOT NULL default '0',
status smallint NOT NULL default '0',
timezone varchar(8) default NULL,
language char(2) NOT NULL default '',
language varchar(12) NOT NULL default '',
picture varchar(255) NOT NULL DEFAULT '',
init varchar(64) default '',
data text default '',
......@@ -703,6 +727,7 @@ INSERT INTO filters VALUES (2,'filter',1,0);
INSERT INTO filters VALUES (3,'filter',3,0);
INSERT INTO variable (name,value) VALUES ('filter_html_1','i:1;');
INSERT INTO locales_meta(locale, name, enabled, isdefault) VALUES('en', 'English', '1', '1');
---
--- Functions
......
......@@ -70,7 +70,9 @@
"2004-08-04" => "update_96",
"2004-08-06" => "update_97",
"2004-08-07" => "update_98",
"2004-08-09" => "update_99"
"2004-08-09" => "update_99",
"2004-08-10" => "update_100",
"2004-08-11" => "update_101"
);
function update_32() {
......@@ -1461,6 +1463,87 @@ function update_99() {
return $ret;
}
function update_100() {
$ret = array();
if ($GLOBALS["db_type"] == "mysql") {
$ret[] = update_sql("CREATE TABLE {locales_source} (
lid int(11) NOT NULL auto_increment,
location varchar(128) NOT NULL default '',
source blob NOT NULL,
PRIMARY KEY (lid)
)");
$ret[] = update_sql("CREATE TABLE {locales_target} (
lid int(11) NOT NULL default '0',
translation blob NOT NULL,
locale varchar(12) NOT NULL default '',
plid int(11) NOT NULL default '0',
plural int(1) NOT NULL default '0',
KEY lid (lid),
KEY lang (locale),
KEY plid (plid),
KEY plural (plural)
)");
$ret[] = update_sql("INSERT INTO {locales_meta} (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1')");
$ret[] = update_sql("ALTER TABLE {users} CHANGE language language varchar(12) NOT NULL default ''");
}
else { // TODO: pgsql support (see database.pgsql for suggestions)
}
return $ret;
}
function update_101() {
include_once 'includes/locale.inc';
// get the language columns
$result = db_query('SELECT * FROM {locales} LIMIT 1');
$fields = array();
if (db_num_rows($result)) {
$columns = array_keys(db_fetch_array($result));
foreach ($columns as $field) {
$fields[$field] = 1;
}
// but not the fixed fields
unset($fields['lid'], $fields['location'], $fields['string']);
// insert locales
$list = _locale_get_iso639_list();
foreach ($fields as $key => $value) {
if (db_result(db_query("SELECT COUNT(lid) FROM {locales} WHERE $key != ''"))) {
if (isset($list[$key])) {
$name = $list[$key][0];
if ($key == 'en') {
$key = 'en-local';
}
db_query("INSERT INTO {locales_meta} (locale, name) VALUES ('%s', '%s')", $key, $name);
}
else {
db_query("INSERT INTO {locales_meta} (locale, name) VALUES ('%s', '%s')", $key, $key);
}
}
}
// get all strings
$result = db_query('SELECT * FROM {locales}');
while($entry = db_fetch_object($result)) {
// insert string if at least one translation exists
$test = 'return $entry->'. implode(' == "" && $entry->', array_keys($fields)) .' == "";';
if (!eval($test)) {
db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $entry->location, $entry->string);
$lid = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s'", $entry->location, $entry->string));
foreach ($fields as $key => $value) {
// insert translation if non-empty
db_query("INSERT INTO {locales_target} (lid, translation, locale) VALUES (%d, '%s', '%s')", $lid->lid, $entry->$key, $key);
}
}
}
}
$ret = array();
$ret[] = update_sql("DROP TABLE {locales}");
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
......
......@@ -505,8 +505,15 @@ function message_na() {
/**
* Initialize the localization system.
*/
function locale_init() {
global $languages, $user;
function locale_initialize() {
global $user;
if (function_exists('locale')) {
$languages = locale_supported_languages();
$languages = $languages['name'];
}
else {
$languages = array();
}
if ($user->uid && $languages[$user->language]) {
return $user->language;
}
......@@ -540,9 +547,10 @@ function locale_init() {
* The translated string.
*/
function t($string, $args = 0) {
global $languages;
$string = ($languages && module_exist('locale') ? locale($string) : $string);
global $locale;
if (function_exists('locale') && $locale != 'en') {
$string = locale($string);
}
if (!$args) {
return $string;
......@@ -841,7 +849,23 @@ function format_rss_item($title, $link, $description, $args = array()) {
* A translated string.
*/
function format_plural($count, $singular, $plural) {
return t($count == 1 ? $singular : $plural, array('%count' => $count));
if ($count == 1) return t($singular);
// get the plural index through the gettext formula
$index = (function_exists('locale')) ? locale_get_plural($count) : -1;
if ($index < 0) { // backward compatibility
return t($plural, array("%count" => $count));
}
else {
switch ($index) {
case "0":
return t($singular);
case "1":
return t($plural, array("%count" => $count));
default:
return t(strtr($plural, array("%count" => '%count['. $index .']')), array('%count['. $index .']' => $count));
}
}
}
/**
......@@ -1814,7 +1838,7 @@ function drupal_eval($code) {
}
// initialize localization system:
$locale = locale_init();
$locale = locale_initialize();
// initialize theme:
$theme = init_theme();
......
......@@ -45,15 +45,6 @@
# If required, update PHP's include path to include your PEAR directory:
// ini_set("include_path", ".:/path/to/pear");
#
# Languages / translation / internationalization:
#
# The first language listed in this associative array will
# automatically become the default language. You can add a language
# but make sure your SQL table, called locales is updated
# appropriately.
$languages = array("en" => "english");
#
# Custom navigation links:
#
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -994,7 +994,8 @@ function node_block($op = 'list', $delta = 0) {
* The link should be an absolute URL.
*/
function node_feed($nodes = 0, $channel = array()) {
global $base_url, $languages;
global $base_url;
$languages = (function_exists('locale')) ? locale_supported_languages() : array();
if (!$nodes) {
$nodes = db_query_range('SELECT nid FROM {node} WHERE promote = 1 AND status = 1 ORDER BY created DESC', 0, 15);
......@@ -1012,7 +1013,7 @@ function node_feed($nodes = 0, $channel = array()) {
'title' => variable_get('site_name', 'drupal') .' - '. variable_get('site_slogan', ''),
'link' => $base_url,
'description' => variable_get('site_mission', ''),
'language' => (($key = reset(array_keys($languages))) ? $key : 'en')
'language' => (($key = reset(array_keys($languages['name']))) ? $key : 'en')
);
$channel = array_merge($channel_defaults, $channel);
......
......@@ -994,7 +994,8 @@ function node_block($op = 'list', $delta = 0) {
* The link should be an absolute URL.
*/
function node_feed($nodes = 0, $channel = array()) {
global $base_url, $languages;
global $base_url;
$languages = (function_exists('locale')) ? locale_supported_languages() : array();
if (!$nodes) {
$nodes = db_query_range('SELECT nid FROM {node} WHERE promote = 1 AND status = 1 ORDER BY created DESC', 0, 15);
......@@ -1012,7 +1013,7 @@ function node_feed($nodes = 0, $channel = array()) {
'title' => variable_get('site_name', 'drupal') .' - '. variable_get('site_slogan', ''),
'link' => $base_url,
'description' => variable_get('site_mission', ''),
'language' => (($key = reset(array_keys($languages))) ? $key : 'en')
'language' => (($key = reset(array_keys($languages['name']))) ? $key : 'en')
);
$channel = array_merge($channel_defaults, $channel);
......
......@@ -109,7 +109,7 @@ function update_info() {
print "</ol>";
print "Notes:";
print "<ol>";
print " <li>If you <strong>upgrade from Drupal 4.4.x</strong>, you will need to create the <code>users_roles</code> table manually before upgrading. To create the <code>users_roles</code> table, issue the following SQL commands:
print " <li>If you <strong>upgrade from Drupal 4.4.x</strong>, you will need to create the <code>users_roles</code> and <code>locales_meta</code> tables manually before upgrading. To create these tables, issue the following SQL commands:
<p>MySQL specific example:
<pre>
......@@ -118,6 +118,15 @@ function update_info() {
rid int(10) unsigned NOT NULL default '0',
PRIMARY KEY (uid, rid)
);
CREATE TABLE locales_meta (
locale varchar(12) NOT NULL default '',
name varchar(64) NOT NULL default '',
enabled int(2) NOT NULL default '0',
isdefault int(2) NOT NULL default '0',
plurals int(1) NOT NULL default '0',
formula varchar(128) NOT NULL default '',
PRIMARY KEY (locale)
);
</pre>
</p>
......@@ -128,6 +137,15 @@ function update_info() {
rid integer NOT NULL default '0',
PRIMARY KEY (uid, rid)
);
CREATE TABLE locales_meta (
locale varchar(12) NOT NULL default '',
name varchar(64) NOT NULL default '',
enabled int4 NOT NULL default '0',
isdefault int4 NOT NULL default '0',
plurals int4 NOT NULL default '0',
formula varchar(128) NOT NULL default '',
PRIMARY KEY (locale)
);
</pre>
</p>
</li>";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment