Closed (won't fix)
Project:
Localegettext
Version:
4.4.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Mar 2005 at 08:28 UTC
Updated:
30 Jan 2013 at 21:04 UTC
Here is a patch to locale.module that allows for multiple translations of the same string. In many languages the same english word og expression can have different meanings, depending on the context.
Ths patch adds the location of the string (filename and line number) to the search for translated strings. This should also give translators who are downloading the .po-files from a running drupal more information about where the string is used than today.
--- locale.module.orig 2005-03-23 08:42:29.000000000 +0100
+++ locale.module 2005-03-23 09:17:47.000000000 +0100
@@ -142,15 +142,39 @@
// We don't have this translation cached, so get it from the DB
else {
- $result = db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.locale = '%s'", $string, $locale);
+ $caller = debug_backtrace();
+ $docroot = realpath($_SERVER['DOCUMENT_ROOT']);
+ $file = ereg_replace($docroot, '', $caller[1]['file']);
+ $line = $caller[1]['line'];
+ $result = db_query("SELECT s.lid, s.location, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.locale = '%s'", $string, $locale);
// Translation found
- if ($trans = db_fetch_object($result)) {
+ while ($trans = db_fetch_object($result)) {
if (!empty($trans->translation)) {
- $locale_t[$string] = $trans->translation;
- $string = $trans->translation;
+ if ($trans->location == "$file:$line") {
+ $locale_t[$string] = $trans->translation;
+ $string = $trans->translation;
+ $match = $trans->lid;
+ $rate = 100;
+ break;
+ }
+ elseif (eregi($file, $trans->location) && ($match < 100)) {
+ $locale_t[$string] = $trans->translation;
+ $string = $trans->translation;
+ $match = $trans->lid;
+ $rate = 75;
+ }
+ else {
+ $locale_t[$string] = $trans->translation;
+ $string = $trans->translation;
+ $match = $trans->lid;
+ $rate = 50;
+ }
}
}
-
+ // We have a translation, but not a full file:line match
+ if (($match) && ($rate < 100)) {
+ $result = db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $match, $locale, $string);
+ }
// Either we have no such source string, or no translation
else {
$result = db_query("SELECT lid, source FROM {locales_source} WHERE source = '%s'", $string);
@@ -162,7 +186,7 @@
}
// We have no such source string
else {
- db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", request_uri(), $string);
+ db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", "$file:$line", $string);
if ($locale) {
$lid = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $string));
db_query("INSERT INTO {locales_target} (lid, locale) VALUES (%d, '%s')", $lid->lid, $locale);
Comments
Comment #1
Olen commentedUhm...
This is not for 4.4.0, but for CVS, but there seems to be a problem with the "version"-select.
Comment #2
Olen commentedI guess this would require some changes to a few of the queries in includes/locale.inc as well, to make them update the corretc string (based on $english + $location.
I'll see what I can do.
Comment #3
Olen commentedAnd here is the patch for locale.inc
I think that is all that is needed.
Comment #4
Olen commentedThere are a few issues with these patches. I am currently sorting out the last few problems, but please do not apply them yet.
New patches with even more features are on their way.
Comment #5
simon georges commentedModule is not active any more.