[yast-commit] r46366 - in /trunk/core: VERSION libycp/src/YCPBuiltinString.cc libycp/src/YCode.cc libycp/src/include/ycp/YCode.h package/yast2-core.changes
Author: mvidner Date: Thu Apr 10 16:53:47 2008 New Revision: 46366 URL: http://svn.opensuse.org/viewcvs/yast?rev=46366&view=rev Log: New builtin: dpgettext ("animals", "/mnt/share/locale", "Giraffe") (fate#2826, by juhliarik). Modified: trunk/core/VERSION trunk/core/libycp/src/YCPBuiltinString.cc trunk/core/libycp/src/YCode.cc trunk/core/libycp/src/include/ycp/YCode.h trunk/core/package/yast2-core.changes Modified: trunk/core/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/VERSION?rev=46366&r1=46365&r2=46366&view=diff ============================================================================== --- trunk/core/VERSION (original) +++ trunk/core/VERSION Thu Apr 10 16:53:47 2008 @@ -1 +1 @@ -2.16.46 +2.16.47 Modified: trunk/core/libycp/src/YCPBuiltinString.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YCPBuiltinString.cc?rev=46366&r1=46365&r2=46366&view=diff ============================================================================== --- trunk/core/libycp/src/YCPBuiltinString.cc (original) +++ trunk/core/libycp/src/YCPBuiltinString.cc Thu Apr 10 16:53:47 2008 @@ -1287,6 +1287,57 @@ } +static YCPValue +s_dpgettext (const YCPString& domain, const YCPString& domain_path, const YCPString& text) +{ + /** + * @builtin dpgettext + * @short Translates the text using the given text domain and path + * @description + * Translates the text using the given text domain into + * the current language and path of localization . + * Path of localization is same than dirname in function bindtextdomain() + * + * This is a special case builtin not intended for general use. + * See _() instead. + * + * @param string textdomain + * @param string dirname + * @param string text + * @return string + * @usage dpgettext ("base", "/texdomain/path", "No") -> "Nie" + */ + + if ((domain.isNull () || domain->isVoid ()) || + (domain_path.isNull () || domain_path->isVoid ()) || + (text.isNull () || text->isVoid ())) + { + return YCPNull (); + } + + // initialize text domain if not done so + string dom = domain->value (); + string dom_path = domain_path->value (); + + // check if domain exist + // it is important to bind domain back (LOCALEDIR) + // if it is already binded + bool known_domain = false; + if (YLocale::findDomain(dom)) + known_domain = true; + + YLocale::bindDomainDir (dom, dom_path); + string result = dgettext (dom.c_str(), text->value().c_str()); + // if it is known domain bind it back to LOCALEDIR + if (known_domain) + YLocale::bindDomainDir (dom, LOCALEDIR); + + return YCPString (result); +} + + + + YCPBuiltinString::YCPBuiltinString () { // must be static, registerDeclarations saves a pointer to it! @@ -1324,6 +1375,7 @@ { "regexptokenize","list <string> (string, string)", (void *)s_regexptokenize }, { "dgettext", "string (string, string)", (void *)s_dgettext}, { "dngettext", "string (string, string, string, integer)", (void *)s_dngettext}, + { "dpgettext", "string (string, string, string)", (void *)s_dpgettext}, { 0 } }; Modified: trunk/core/libycp/src/YCode.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YCode.cc?rev=46366&r1=46365&r2=46366&view=diff ============================================================================== --- trunk/core/libycp/src/YCode.cc (original) +++ trunk/core/libycp/src/YCode.cc Thu Apr 10 16:53:47 2008 @@ -534,6 +534,7 @@ return YCPString (ret); } +// FIXME: why we use pair string:bool in domains if we used only true value? YLocale::t_uniquedomains::const_iterator YLocale::setDomainStatus (const string& domain, bool status) @@ -549,6 +550,12 @@ return domains.find (domain.c_str ()); } +bool +YLocale::findDomain(const string& domain) +{ + return (domains.find (domain.c_str ()) == domains.end ()) ? false : true; +} + void YLocale::ensureBindDomain (const string& domain) @@ -556,13 +563,22 @@ if (domains.find (domain.c_str ()) == domains.end () || ! domains[domain.c_str ()]) { + bindDomainDir (domain, LOCALEDIR); + } +} + + +void +YLocale::bindDomainDir (const string& domain, const string& domain_path) +{ + #if DO_DEBUG - y2debug ("going to bind a domain %s", domain.c_str() ); + y2debug ("going to bind a domain %s with path %s", domain.c_str(), domain_path.c_str()); #endif - bindtextdomain (domain.c_str (), LOCALEDIR); - bind_textdomain_codeset (domain.c_str (), "UTF-8"); - setDomainStatus (domain, true); - } + bindtextdomain (domain.c_str (), domain_path.c_str()); + bind_textdomain_codeset (domain.c_str (), "UTF-8"); + setDomainStatus (domain, true); + } // ------------------------------------------------------------------ Modified: trunk/core/libycp/src/include/ycp/YCode.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/include/ycp/YCode.h?rev=46366&r1=46365&r2=46366&view=diff ============================================================================== --- trunk/core/libycp/src/include/ycp/YCode.h (original) +++ trunk/core/libycp/src/include/ycp/YCode.h Thu Apr 10 16:53:47 2008 @@ -262,7 +262,8 @@ static t_uniquedomains domains; // keep every textdomain only once static t_uniquedomains::const_iterator setDomainStatus (const string& domain, bool status); static void ensureBindDomain (const string& domain); - + static void bindDomainDir (const string& domain, const string& domain_path); + static bool findDomain(const string& domain); YLocale (const char *locale, const char *textdomain); YLocale (bytecodeistream & str); ~YLocale (); Modified: trunk/core/package/yast2-core.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/package/yast2-core.changes?rev=46366&r1=46365&r2=46366&view=diff ============================================================================== --- trunk/core/package/yast2-core.changes (original) +++ trunk/core/package/yast2-core.changes Thu Apr 10 16:53:47 2008 @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Thu Apr 10 16:53:17 CEST 2008 - mvidner@suse.cz + +- New builtin: dpgettext ("animals", "/mnt/share/locale", "Giraffe") + (fate#2826, by juhliarik). +- 2.16.47 + +------------------------------------------------------------------- Wed Apr 09 11:16:34 CEST 2008 - aschnell@suse.de - added new builtin sublist -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
mvidner@svn.opensuse.org