Dumped on 2024-12-23

Index of database - gnumed_v21


Table: curr_lang

holds the currently selected per-user default language for fixed strings in the database

curr_lang Structure
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

 

curr_lang Constraints
Name Constraint
user_must_exist CHECK ((gm.user_exists(db_user) IS TRUE))

Index - Schema i18n


Table: keys

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

keys Structure
F-Key Name Type Description
pk serial PRIMARY KEY
orig text UNIQUE NOT NULL

Index - Schema i18n


Table: translations

this table holds all the translated strings

translations Structure
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>

 

translations Constraints
Name Constraint
i18n_translations_sane_trans CHECK ((trans <> orig))

Index - Schema i18n


View: v_missing_translations

lists per language which strings are lacking a translation

v_missing_translations Structure
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
           )
     )
);

Index - Schema i18n


Function: _(text)

Returns: text

Language: SQL

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())

Function: _(text, text)

Returns: text

Language: PLPGSQL

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;

Function: force_curr_lang(text)

Returns: boolean

Language: PLPGSQL

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;

Function: get_curr_lang()

Returns: text

Language: SQL

select i18n.get_curr_lang(CURRENT_USER)

Function: get_curr_lang(text)

Returns: text

Language: SQL

select lang from i18n.curr_lang where db_user = $1

Function: i18n(text)

Returns: text

Language: PLPGSQL

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;

Function: set_curr_lang(text)

Returns: boolean

Language: PLPGSQL

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;

Function: set_curr_lang(text, name)

Returns: boolean

Language: PLPGSQL

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;

Function: tx_or_null(text)

Returns: text

Language: SQL

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())

Function: tx_or_null(text, text)

Returns: text

Language: PLPGSQL

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;

Function: unset_curr_lang()

Returns: void

Language: SQL

unset the db language for the current user

select i18n.unset_curr_lang(CURRENT_USER);

Function: unset_curr_lang(name)

Returns: void

Language: PLPGSQL

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;

Function: untranslate(text, text)

Returns: text

Language: PLPGSQL

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;

Function: upd_tx(text, text)

Returns: boolean

Language: SQL

select i18n.upd_tx((select i18n.get_curr_lang()), $1, $2)

Function: upd_tx(text, text, text)

Returns: boolean

Language: PLPGSQL

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

W3C HTML 4.01 Strict