Dumped on 2024-11-22
holds the currently selected per-user default language for fixed strings in the database
F-Key | Name | Type | Description |
---|---|---|---|
pk | serial | PRIMARY KEY | |
db_user | name |
UNIQUE
NOT NULL
DEFAULT "current_user"()
The database account this language setting applies to. |
|
lang | text | NOT NULL |
Name | Constraint |
---|---|
user_must_exist | CHECK ((gm.user_exists(db_user) IS TRUE)) |
this table holds all the original strings that need translation so give this to your language teams, the function i18n.i18n() will take care to enter relevant strings into this table, the table table does NOT play any role in runtime translation activity
F-Key | Name | Type | Description |
---|---|---|---|
pk | serial | PRIMARY KEY | |
orig | text | UNIQUE NOT NULL |
this table holds all the translated strings
F-Key | Name | Type | Description |
---|---|---|---|
pk | serial | PRIMARY KEY | |
lang | text |
UNIQUE#1
NOT NULL
the language (corresponding to i18n.curr_lang for a given user) that this translation belongs to |
|
orig | text |
UNIQUE#1
NOT NULL
the original, untranslated string, used as the search key. |
|
trans | text |
NOT NULL
the translation of <orig> into <lang> |
Name | Constraint |
---|---|
i18n_translations_sane_trans | CHECK ((trans <> orig)) |
lists per language which strings are lacking a translation
F-Key | Name | Type | Description |
---|---|---|---|
lang | text | ||
orig | text |
SELECT icl.lang , ik.orig FROM ( SELECT DISTINCT ON (curr_lang.lang) curr_lang.lang FROM i18n.curr_lang ) icl , i18n.keys ik WHERE (NOT (ik.orig IN ( SELECT translations.orig FROM i18n.translations ) ) );
will return either the translation into i18n.curr_lang.lang for the current user or the input, created in public schema for easy access
select i18n._($1, i18n.get_curr_lang())
will return either the translation into <lang>::text (2nd argument) for the current user or the input, created in public schema for easy access, will fallback to "xx" if xx_XX does not exist
DECLARE _orig alias for $1; _lang alias for $2; trans_str text; BEGIN select into trans_str trans from i18n.translations where lang = _lang and orig = _orig; if not found then -- reduce xx_XX@YY to xx select into trans_str trans from i18n.translations where lang = regexp_replace(_lang, '_.*$', '') and orig = _orig; if not found then return _orig; end if; -- if not found then -- -- check "generic" dummy translation used to work around accentuation problems -- select into trans_str trans from i18n.translations where lang = 'generic' and orig = _orig; -- -- if not found then -- return _orig; -- end if; -- end if; end if; return trans_str; END;
force preferred language to some language: - for "current user"
DECLARE _lang ALIAS FOR $1; BEGIN raise notice 'Forcing current language to [%] without checking for translations..', _lang; delete from i18n.curr_lang where user = CURRENT_USER; insert into i18n.curr_lang(lang) values (_lang); return 1; END;
select i18n.get_curr_lang(CURRENT_USER)
select lang from i18n.curr_lang where db_user = $1
insert original strings into i18n.keys for later translation
DECLARE original ALIAS FOR $1; BEGIN if not exists(select pk from i18n.keys where orig = original) then insert into i18n.keys (orig) values (original); end if; return original; END;
set preferred language: - for "current user" - only if translations for this language are available
DECLARE _lang ALIAS FOR $1; BEGIN if exists(select pk from i18n.translations where lang = _lang) then delete from i18n.curr_lang where user = CURRENT_USER; insert into i18n.curr_lang (lang) values (_lang); return true; end if; raise notice 'Cannot set current language to [%]. No translations available.', _lang; return false; END;
set language to first argument for the user named in the second argument if translations are available
DECLARE _lang ALIAS FOR $1; _db_user ALIAS FOR $2; lang_has_tx boolean; BEGIN select into lang_has_tx exists(select pk from i18n.translations where lang = _lang); if lang_has_tx is False then raise notice 'Cannot set current language to [%]. No translations available.', _lang; return False; end if; delete from i18n.curr_lang where db_user = _db_user; insert into i18n.curr_lang (db_user, lang) values (_db_user, _lang); return true; END;
will return either the translation into i18n.curr_lang.lang for the current user or null
select i18n.tx_or_null($1, i18n.get_curr_lang())
will return either the translation into language <text> (2nd argument) or null
DECLARE _orig alias for $1; _lang alias for $2; trans_str text; BEGIN select into trans_str trans from i18n.translations where lang = _lang and orig = _orig; if not found then return null; end if; return trans_str; END;
unset the db language for the current user
select i18n.unset_curr_lang(CURRENT_USER);
unset the db language for a user (thereby reverting to the default English)
BEGIN delete from i18n.curr_lang where db_user = $1; return; END;
Return "original" from a "translated" string (1st argument) as per language (2nd argument).
DECLARE _trans alias for $1; _lang alias for $2; _orig text; BEGIN select orig into _orig from i18n.translations where trans = _trans and lang = _lang; return _orig; END;
select i18n.upd_tx((select i18n.get_curr_lang()), $1, $2)
declare _lang alias for $1; _orig alias for $2; _trans alias for $3; _tmp text; begin if _lang is null then raise notice 'i18n.upd_tx(text, text, text): Cannot create translation for language <NULL>.'; return False; end if; if _trans = _orig then raise notice 'i18n.upd_tx(text, text, text): Original = translation. Skipping.'; return True; end if; select into _tmp '1' from i18n.keys where orig = _orig; if not found then raise notice 'i18n.upd_tx(text, text, text): [%] not found in i18n.keys. Creating entry.', _orig; insert into i18n.keys (orig) values (_orig); end if; delete from i18n.translations where lang = _lang and orig = _orig; insert into i18n.translations (lang, orig, trans) values (_lang, _orig, _trans); raise notice 'i18n.upd_tx(%: [%] ==> [%])', _lang, _orig, _trans; return True; end;
Generated by PostgreSQL Autodoc