diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index a47fd9368..85402811b 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -4,6 +4,7 @@ 2005-06-05 Alex Roitman * configure.in: Bump up the version number. + * src/Utils.py (strip_context): Add function. 2005-06-05 Don Allingham * src/DateHandler.py: fixed initialization of parser class diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 6b8066774..ea0c3f8e1 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -27,6 +27,7 @@ #------------------------------------------------------------------------- import os import locale +from gettext import gettext as _ #------------------------------------------------------------------------- # @@ -52,13 +53,6 @@ import GrampsMime import NameDisplay import Date -#------------------------------------------------------------------------- -# -# internationalization -# -#------------------------------------------------------------------------- -from gettext import gettext as _ - #------------------------------------------------------------------------- # # modified flag @@ -400,7 +394,7 @@ def search_for(name): #------------------------------------------------------------------------- # -# Change label apperance +# Change label appearance # #------------------------------------------------------------------------- def bold_label(label,widget=None): @@ -793,3 +787,26 @@ def get_type_converter_by_name(val_str): elif val_str in ('str','unicode'): return unicode return unicode + +def strip_context(msgid,sep='|'): + """ + Strip the context used for resolving translation ambiguities. + + The translation of msgid is returned unless the translation is + not available and the msgid contains the separator. In that case, + the returned value is the portion of msgid following the last + separator. Default separator is '|'. + + @param msgid: The string to translated. + @type msgid: unicode + @param sep: The separator marking the context. + @type sep: unicode + @return: Translation or the original with context stripped. + @rtype: unicode + + """ + msgval = _(msgid) + sep_idx = msgid.rfind(sep) + if msgval == msgid and sep_idx != -1: + msgval = msgid[sep_idx+1:] + return msgval