![]() | ![]() | ![]() | libxfce4util Reference Manual | ![]() |
---|
Internationalization — Internationalization and Localization Support Functions
#include <libxfce4util/libxfce4util.h> #define _ (s) #define N_ (s) #define Q_ (s) #define xfce_textdomain (package, localedir, encoding) G_CONST_RETURN gchar* xfce_strip_context (const gchar *msgid, const gchar *msgval); gchar* xfce_get_file_localized (const gchar *filename); gchar* xfce_get_file_localized_r (gchar *buffer, gsize length, const gchar *filename); gchar* xfce_get_dir_localized (const gchar *directory); gchar* xfce_get_dir_localized_r (gchar *buffer, gsize length, const gchar *directory); gchar* xfce_get_path_localized (gchar *dst, gsize size, const gchar *paths, const gchar *filename, GFileTest test); #define XFCE_LOCALE_FULL_MATCH #define XFCE_LOCALE_NO_MATCH guint xfce_locale_match (const gchar *locale1, const gchar *locale2);
Provides functions and preprocessor macros to aid the application developers making his software localizable. It also offers functionality similar to the one introduced in GLib 2.4 and referenced as gi18n. This includes the Q_ gettext macro and the xfce_strip_context function.
#define _(s)
Marks a string for translation, gets replaced with the translated string at runtime.
s : | string to translate. |
#define N_(s)
Marks a string for translation, gets replaced with the untranslated string at runtime. This is useful in situations where the translated strings can't be directly used, e.g. in string array initializers.
s : | the string to be translated. |
#define Q_(s)
Like _(), but applies xfce_strip_context() to the translation. This has the advantage that the string can be adorned with a prefix to guarantee uniqueness and provide context to the package translator.
One use case given in the gettext manual is GUI translation, where one could e.g. disambiguate two "Open" menu entries as "File|Open" and "Printer|Open". Another use case is the string "Russian" which may have to be translated differently depending on whether it is the name of a character set or a language. This could be solved by using "charset|Russian" and "language|Russian".
s : | the string to be translated, with a '|'-separated prefix which must not be translated by the package translators. |
#define xfce_textdomain(package, localedir, encoding)
Binds the current text domain for package to localedir and sets encoding.
package : | |
localedir : | |
encoding : |
G_CONST_RETURN gchar* xfce_strip_context (const gchar *msgid, const gchar *msgval);
Portable replacement for g_strip_context() introduced in GLib 2.4. You prefer this method over g_strip_context() cause it allows your software to be used with older versions of GLib as well, though libxfce4util also defines a macro named g_strip_context() that simply calls xfce_strip_context if an older GLib version is detected.
msgid : | a string that may be translated. |
msgval : | a possible translation for msgid or the same as msgid. |
Returns : | msgval, unless msgval is identical to msgid and contains a '|' character, in which case a pointer to the substring of msgid after the first '|' character is returned |
Since 4.2
gchar* xfce_get_file_localized (const gchar *filename);
Checks if theres a version of filename which is localized to the current locale. This is done by appending the full locale name to filename, separated by a '.'. If theres no file of that name, it retries using the full locale name without the encoding (if any), then without the qualifier (if any) and at last the base locale is tried. If all of those fails, a copy of filename is returned.
filename : | name of a file to look for a localized version. |
Returns : | path of the localized file or copy of filename if no such file exists. Returned string should be freed using g_free(). |
gchar* xfce_get_file_localized_r (gchar *buffer, gsize length, const gchar *filename);
Similar in functionality to xfce_get_file_localized, but stores the result in buffer instead of allocating a new buffer.
buffer : | destination buffer to store the localized filename to. |
length : | size of buffer in bytes. |
filename : | name of a file to look for a localized version. |
Returns : | pointer to buffer or NULL on error. |
gchar* xfce_get_dir_localized (const gchar *directory);
Similar to xfce_get_file_localized, but works on directory instead of a file.
directory : | directory name to check for a localized variant. |
Returns : | path of the localized directory name or copy of directory if no such directory exists. Returned string should be freed using g_free(). |
gchar* xfce_get_dir_localized_r (gchar *buffer, gsize length, const gchar *directory);
Similar to xfce_get_file_localized_r, but works on directory instead of regular file.
buffer : | destination buffer to store the localized filename to. |
length : | size of buffer in bytes. |
directory : | name of directory to check for localized variant of. |
Returns : | pointer to buffer or NULL on error. |
gchar* xfce_get_path_localized (gchar *dst, gsize size, const gchar *paths, const gchar *filename, GFileTest test);
paths is a ':'-separated list of pathnames.
F - The filename L - The language string, as returned by setlocale(LC_MESSAGES, NULL) l - The language component of the language string N - application name
Example paths:
/usr/local/lib/L/F:/usr/local/share/N/l/F
dst : | destination buffer. |
size : | size of dst in bytes. |
paths : | |
filename : | |
test : | |
Returns : |
#define XFCE_LOCALE_FULL_MATCH 50
Returned by xfce_locale_match in case of a full match.
#define XFCE_LOCALE_NO_MATCH 0
Returned by xfce_locale_match if no match could be detected.
guint xfce_locale_match (const gchar *locale1, const gchar *locale2);
The locale is of the general form LANG_COUNTRY.ENCODING @ MODIFIER, where each of COUNTRY, ENCODING and MODIFIER can be absent.
The match is done by actually removing the rightmost element one by one. This is not entirely according to the freedesktop.org specification, but much easier. Will probably be fixed in the future.
locale1 : | the current locale value as returned by setlocale(LC_MESSAGES,NULL). |
locale2 : | the locale value to match against. |
Returns : | an integer value indicating the level of matching, where the constant XFCE_LOCALE_FULL_MATCH indicates a full match and XFCE_LOCALE_NO_MATCH means no match. Every other value indicates a partial match, the higher the value, the better the match. You should not rely on any specific value besides the constants XFCE_LOCALE_FULL_MATCH and XFCE_LOCALE_NO_MATCH, since the range of returned values may change in the future. |
Since 4.2
<< Standard Macros | Xfce Core Application support >> |