Retrieving i18n data with fallback language
try something like this:
SELECT
e.key,COALESCE(o.value,e.value)
FROM Translation e
LEFT OUTER JOIN Translation o ON e.key=o.key and o.language_code='nl'
WHERE e.language_code='en'
Symfony i18n table: Ways to get fallback default value?
Try something like this:
$q = Doctrine_Query::create()
->from('Cities c')
->leftJoin('c.Translation ct WITH lang IN(?)', array(array('es_ES', 'en_US')))
->execute();
iOS i18n default fallback language
In the Info pane for your target, check the "Localization native development region" (CFBundleDevelopmentRegion
). This is probably en
(since that's the default). This is the ultimate fall-back region. You should probably set this to pt
.
How to obtain the language of the string returned by i18next.t?
internally i18next has a resolve function that returns the used language…
You may try to access i18next.translator.resolve(key, options)
but like said this is undocumented and not an official public interface.
Edit: Since v21.7.0 there is a new option returnDetails
that can be set to true to get all relevant information.
const resolved = t('key', { returnDetails: true });
resolved.res;
resolved.usedKey;
resolved.exactUsedKey;
resolved.usedNS;
resolved.usedLng;
JQuery.i18n replaces none existing key with the key name instead of the fallback text
It seems to be a bug! I was checking the JQuery.i18n code and I found the problem.
It's all in jquery.i18n.js
. It starts with this code in line #169:
if ( message === '' ) {
message = key;
}
The if
is executed when there is no text defined for the key and then the message becomes the key.
I commented the assignment:
if ( message === '' ) {
// message = key;
}
Then I had to change in line #244 this code:
} else {
$this.text( i18n.parse( messageKey ) );
}
to
} else {
const translatedText = i18n.parse( messageKey );
if ( '' !== translatedText ) {
$this.text( translatedText );
}
}
Now the fallback text does work. The following comment in line number 165 seems to confirm it's a bug and the developer knows it but somehow he lives with it:
// FIXME: This changes the state of the I18N object,
// should probably not change the 'this.parser' but just
// pass it to the parser.
If you apply this hack so consider also the modifications for html
and other tags
few lines above.
How to use the I18n fallback features in Rails 3
When a :default option is given, its value will be returned if the translation is missing:
I18n.t :missing, :default => 'Not here'
# => 'Not here'
More info here
SQL - Fallback to default language when translate does not exist
LEFT JOIN
the language table twice. The first time for wanted language, the second time for fallback value. Use COALESCE
to pick wanted language if available, otherwise fallback language.
SELECT coalesce(l1.[value], l2.[value])
FROM tbl_i18n i
JOIN tbl_products p ON p.text_id = i.text_FK
LEFT JOIN tbl_languages l1 ON l.id = i.language_FK AND i.language_FK = 2
LEFT JOIN tbl_languages l2 ON l.id = i.language_FK AND i.language_FK = 1;
Related Topics
Conditional SQLite Check Constraint
Postgresql - Query from Bash Script as Database User 'Postgres'
How to Avoid "Table Mutating" Errors
Odata Case In-Sensitive Filtering in Web API
Suppress Output of Variables Substitution in SQLplus
Oracle Insert into Table2 Then Delete from Table1, Exception If Fail
MySQL Views - When to Use & When Not To
Sql-Only Find Time and Not Date in Access Date/Time Field
Lock Escalation - What's Happening Here
How to Update in SQLite Using a Left Join to Select Candidate Rows
Splitting a Comma-Separated Field in Postgresql and Doing a Union All on All the Resulting Tables
T-Sql: Separate String into Multiple Columns
Delete Oldest Records from Database
Need to Find Average Processing Time Between All Timestamp Records in Oracle SQL
How to Display Oracle Schema Size with SQL Query
How to Run .SQL File in Oracle SQL Developer Tool to Import Database