drupal/modules/locale.module

147 lines
7.8 KiB
Plaintext
Raw Normal View History

<?php
function locale_help() {
?>
<P>Normally programs are written and documented in English, and use English to interact with users. This is true for a great deal of websites. However, most people are less comfortable with English than with their own native language, and would prefer to use their mother tongue as much as possible. Many people love see their website showing a lot less of English, and far more of their own language.</P>
<P>Therefore drupal provides a framework to setup a multi-lingual website, or to overwrite the default texts in English. We explored the various alternatives to support internationalization and decided to design the framework in such a way that the impact of internationalization on drupal's sources is minimized, modular and that it doesn't require a HTML or PHP wizard to maintain translations. Maintaining translations had to be simple so it became as easy as filling out forms on the administration page. A side effect is that translation support adds significant overhead to the dynamic generation of your website. If you don't need translation support, consider to turning it off from the "conf" section.</P>
<H3>How to translate texts</H3>
<P>The actual translation starts at the "overview" of the locale page of the administration pages. To allow a user to maintain the translations, he obviously needs access to the locale module. See the account documentation for more information on roles and permissions.</P>
<P>At the locale page, users with the proper access rights will see the various texts that need translation on the left column of the table.</P>
<P>Below the text you can see an URI where this text shows up one your site. Changes are most of these texts will be used and displayed on more than one page, though only one example URI is presented.</P>
<P>The second column displays the supported languages as defined in the configuration file. See below for more information on how to support new languages. If the symbol for a language is seen like <strike>this</strike>, it means that this entry still needs to be translated into that language. If not, it has been translated already.</P>
<P>To add or change a translation click the "edit locale" link in the third column, the "operations" column. You'll be presented the original text and fields for translation in the supported languages. Enter the translations and confirm by clicking the "Save translations" button. The translations need not be accurate; they are for your site so you can choose what to show to your users.</P>
<P>To delete a translation, click the "delete locale" link at the overview page and the translation will be immediately deleted without confirmation. Deleting translations is convenient for removing texts that belonged to an obsolete module.</P>
<P>In some texts special strings such as "%a" and "%b" show up. Those get replaced by some string at run-time when Drupal dynamically generate pages. You can find out which string this is by looking at the page where the text appears. This is where the above mentioned URI can come in handy.</P>
<H3>How to add new languages</H3>
<P>Adding a new language requires you to edit your configuration file and to edit your SQL database. Assuming you want to support Dutch (ISO 639 code: "nl") and French (ISO 639 code: "fr"), you add the following line to your configuration file's <CODE>$languages</CODE>-variable:</P>
<PRE>
$languages = array("nl" => "Dutch / Nederlands", "fr" => "French / Francais");
</PRE>
<P>Note that the default language must come first and that if you want to overwrite the default text you can add an entry for English (ISO 639 code: "en"):</P>
<PRE>
$languages = array("en" => "English", "nl" => "Dutch / Nederlands", "fr" => "French / Francais");
</PRE>
<P>After having edited your configuration file, make sure your SQL table "locales" has the required database fields setup to host your new translations. You can add the required rows to your "locales" table from the MySQL prompt:</P>
<PRE>
mysql> ALTER TABLE locales ADD en TEXT DEFAULT '' NOT NULL;
mysql> ALTER TABLE locales ADD nl TEXT DEFAULT '' NOT NULL;
mysql> ALTER TABLE locales ADD fr TEXT DEFAULT '' NOT NULL;
</PRE>
<?php
}
function locale_perm() {
return array("administer locales");
}
function locale_link($type) {
if ($type == "admin" && user_access("administer locales")) {
$links[] = "<a href=\"admin.php?mod=locale\">locales</a>";
}
return $links ? $links : array();
}
function locale_conf_options() {
return form_select(t("Locale support"), "locale", variable_get("locale", 0), array("Disabled", "Enabled"), t("Disable locale support if your site does not require translation or internationalization support."));
}
function locale_delete($id) {
db_query("DELETE FROM locales WHERE id = '$id'");
}
function locale_save($id, $edit) {
foreach ($edit as $key=>$value) {
db_query("UPDATE locales SET $key = '". check_input($value) ."' WHERE id = '$id'");
}
}
function locale_edit($id) {
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
global $languages, $REQUEST_URI;
$result = db_query("SELECT * FROM locales WHERE id = '$id'");
if ($translation = db_fetch_object($result)) {
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
$form .= form_item(t("Original text"), "<PRE>". wordwrap(check_output($translation->string)) ."</PRE>");
foreach ($languages as $code=>$language) $form .= (strlen($translation->string) > 30) ? form_textarea($language, $code, $translation->$code, 50, 10) : form_textfield($language, $code, $translation->$code, 50, 128);
$form .= form_hidden("id", $id);
$form .= form_submit("Save translations");
return form($REQUEST_URI, $form);
}
}
function locale_languages($translation) {
global $languages, $na;
if (count($languages)) {
foreach ($languages as $key=>$value) {
$output .= ($translation->$key) ? "$key " : "<STRIKE>$key</STRIKE> ";
}
return $output;
}
return $na;
}
function locale_overview() {
if (variable_get("locale", 0)) {
$result = db_query("SELECT * FROM locales ORDER BY string");
This a rather large commit that needs a lot of fine-tuning. If you update, you'll break your site as you need switching from structure to index.module: so this can be considered an intermediate commit. If you upgrade, and you are welcome to, just create a collection called "section" (for now) and assign your nodes some attributes in the described format. Feedback and bugreports are welcomed. Questions will be answered. CHANGES: - comment system: + when replying to a node (rather then to a comment), that node is displayed above the reply form. + when replying to a comment (rather then to a node), that comment is displayd above the reply form. - removed structure.inc, removed structure.module. - node.inc: + added 2 new node functions called 'node_attribute_edit()' and 'node_attribute_save()' used to 'hook in' any indexing system including your home-brewed stuff if you'd want to. Currently, index.module is the facto default index system. See story.module for usage. - book.module, story.module, poll.module, page.module, forum.module: + added preview functionality to administration section (via node module). + removed all references to structure.inc (category, topic). - moderate.module: + removed all references to structure.inc (category, topic). - book.module, story.module, page.module, forum.module: + increased the sizes of some textareas. - submit.php: + removed all references to structure.inc (category, topic). - marvin.theme: + removed dead code: function story() was depricated. - unconed.theme: + removed hardcoded references to drop.org. - marvin.theme, unconed.theme, jeroen.theme, yaroon.theme, example.theme: + removed all references to structure.inc (category, topic). TODO: - file.module, trip_link.module: + update preview functionality: see story.module for example. + remove references to 'cid' and 'tid', use 'attribute' instead: see story.module for example. - extend and build upon index.module as well as making it configurable
2001-06-10 15:01:20 +00:00
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>string</TH><TH>languages</TH><TH COLSPAN=\"2\">operations</TH><TR>\n";
while ($locale = db_fetch_object($result)) {
$languages = locale_languages($locale);
$output .= " <TR><TD>". check_output($locale->string) ."<BR><SMALL><I>$locale->location</I></SMALL></TD><TD ALIGN=\"center\">$languages</TD><TD NOWRAP><A HREF=\"admin.php?mod=locale&op=edit&id=$locale->id\">edit locale</A></TD><TD NOWRAP><A HREF=\"admin.php?mod=locale&op=delete&id=$locale->id\">delete locale</A></TD></TR>";
}
$output .= "</TABLE>\n";
This a rather large commit that needs a lot of fine-tuning. If you update, you'll break your site as you need switching from structure to index.module: so this can be considered an intermediate commit. If you upgrade, and you are welcome to, just create a collection called "section" (for now) and assign your nodes some attributes in the described format. Feedback and bugreports are welcomed. Questions will be answered. CHANGES: - comment system: + when replying to a node (rather then to a comment), that node is displayed above the reply form. + when replying to a comment (rather then to a node), that comment is displayd above the reply form. - removed structure.inc, removed structure.module. - node.inc: + added 2 new node functions called 'node_attribute_edit()' and 'node_attribute_save()' used to 'hook in' any indexing system including your home-brewed stuff if you'd want to. Currently, index.module is the facto default index system. See story.module for usage. - book.module, story.module, poll.module, page.module, forum.module: + added preview functionality to administration section (via node module). + removed all references to structure.inc (category, topic). - moderate.module: + removed all references to structure.inc (category, topic). - book.module, story.module, page.module, forum.module: + increased the sizes of some textareas. - submit.php: + removed all references to structure.inc (category, topic). - marvin.theme: + removed dead code: function story() was depricated. - unconed.theme: + removed hardcoded references to drop.org. - marvin.theme, unconed.theme, jeroen.theme, yaroon.theme, example.theme: + removed all references to structure.inc (category, topic). TODO: - file.module, trip_link.module: + update preview functionality: see story.module for example. + remove references to 'cid' and 'tid', use 'attribute' instead: see story.module for example. - extend and build upon index.module as well as making it configurable
2001-06-10 15:01:20 +00:00
return $output;
}
This a rather large commit that needs a lot of fine-tuning. If you update, you'll break your site as you need switching from structure to index.module: so this can be considered an intermediate commit. If you upgrade, and you are welcome to, just create a collection called "section" (for now) and assign your nodes some attributes in the described format. Feedback and bugreports are welcomed. Questions will be answered. CHANGES: - comment system: + when replying to a node (rather then to a comment), that node is displayed above the reply form. + when replying to a comment (rather then to a node), that comment is displayd above the reply form. - removed structure.inc, removed structure.module. - node.inc: + added 2 new node functions called 'node_attribute_edit()' and 'node_attribute_save()' used to 'hook in' any indexing system including your home-brewed stuff if you'd want to. Currently, index.module is the facto default index system. See story.module for usage. - book.module, story.module, poll.module, page.module, forum.module: + added preview functionality to administration section (via node module). + removed all references to structure.inc (category, topic). - moderate.module: + removed all references to structure.inc (category, topic). - book.module, story.module, page.module, forum.module: + increased the sizes of some textareas. - submit.php: + removed all references to structure.inc (category, topic). - marvin.theme: + removed dead code: function story() was depricated. - unconed.theme: + removed hardcoded references to drop.org. - marvin.theme, unconed.theme, jeroen.theme, yaroon.theme, example.theme: + removed all references to structure.inc (category, topic). TODO: - file.module, trip_link.module: + update preview functionality: see story.module for example. + remove references to 'cid' and 'tid', use 'attribute' instead: see story.module for example. - extend and build upon index.module as well as making it configurable
2001-06-10 15:01:20 +00:00
else {
return status("locale disabled.");
}
}
function locale_admin() {
global $id, $edit, $op;
if (user_access("administer locales")) {
print "<SMALL><A HREF=\"admin.php?mod=locale\">overview</A> | <A HREF=\"admin.php?mod=locale&op=help\">help</A></SMALL><HR>\n";
switch ($op) {
case "delete":
print status(locale_delete(check_input($id)));
print locale_overview();
break;
case "help":
print locale_help();
break;
case "edit":
print locale_edit(check_input($id));
break;
case "Save translations":
print locale_save(check_input($id), $edit);
// fall through
default:
print locale_overview();
}
}
else {
print message_access();
}
}
function locale($string) {
global $locale;
2001-05-20 16:49:27 +00:00
if (variable_get("locale", 0)) {
2001-02-17 16:26:48 +00:00
$result = db_query("SELECT id, $locale FROM locales WHERE STRCMP(string, '". addslashes($string) ."') = 0");
if ($translation = db_fetch_object($result)) $string = ($translation->$locale) ? check_output($translation->$locale) : $string;
else db_query("INSERT INTO locales (string, location) VALUES ('". addslashes($string) ."', '". check_input(getenv("REQUEST_URI")) ."')");
}
return $string;
}
?>