📄 i18n.cpp
字号:
/************************************************************************* * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * *************************************************************************/#include "i18n.h"/** * Initialize the i18n subsystem. * Will be called by libsmtp++ when the library is loaded * but must be called again if messages that belongs to * another textdomain than "libsmtp++" should be translated. * * @param textdomain The textdomain that should be added. * @param locale_dir The directory that contains the message * files for this textdomain. */void I18N::init (const string &textdomain, const string &locale_dir){ bindtextdomain (textdomain.c_str (), locale_dir.c_str ()); setlocale (LC_ALL,"");}/** * Translates the string msgid. * The string msgid will be translated using the * glibc gettext() function. Additionally the string * can include special substitution characters, which * will be substituted with the strings in the array * params. * EG: "This is a test arg $0, and this is another one: $1" * $0 will be substituted by params[0], $1 will be substituted * by params[1], etc. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @param params The strings that should be inserted into * the translated message. * @param count The size of the array params. * @returns The translated string. */string I18N::i18n ( const string &textdomain, const string &msgid, string params[], unsigned int count ){ string i18n_msg = dgettext (textdomain.c_str (), msgid.c_str ()); unsigned int idx = 0; unsigned int pos = 0; while ((pos = i18n_msg.find ("$"+String::itoa (idx))) != string::npos) { if (idx < count) { int len = String::itoa (idx).length () + 1; i18n_msg.replace (pos, len, params[idx]); } idx++; } return (i18n_msg);}/** * The same as the first method, just with only five * parameters. * Just for your convenience. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @param param1 Substitution string for $0. * @param param2 Substitution string for $1. * @param param3 Substitution string for $2. * @param param4 Substitution string for $3. * @param param5 Substitution string for $4. * @returns The translated string. */string I18N::i18n ( const string &textdomain, const string &msgid, const string ¶m1, const string ¶m2, const string ¶m3, const string ¶m4, const string ¶m5 ){ string params[] = { param1, param2, param3, param4, param5 }; return (I18N::i18n (textdomain, msgid, params, 5));}/** * The same as the first method, just with only four * parameters. * Just for your convenience. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @param param1 Substitution string for $0. * @param param2 Substitution string for $1. * @param param3 Substitution string for $2. * @param param4 Substitution string for $3. * @returns The translated string. */string I18N::i18n ( const string &textdomain, const string &msgid, const string ¶m1, const string ¶m2, const string ¶m3, const string ¶m4 ){ string params[] = { param1, param2, param3, param4 }; return (I18N::i18n (textdomain, msgid, params, 4));}/** * The same as the first method, just with only three * parameters. * Just for your convenience. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @param param1 Substitution string for $0. * @param param2 Substitution string for $1. * @param param3 Substitution string for $2. * @returns The translated string. */string I18N::i18n ( const string &textdomain, const string &msgid, const string ¶m1, const string ¶m2, const string ¶m3 ){ string params[] = { param1, param2, param3 }; return (I18N::i18n (textdomain, msgid, params, 3));}/** * The same as the first method, just with only two * parameters. * Just for your convenience. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @param param1 Substitution string for $0. * @param param2 Substitution string for $1. * @returns The translated string. */string I18N::i18n ( const string &textdomain, const string &msgid, const string ¶m1, const string ¶m2 ){ string params[] = { param1, param2 }; return (I18N::i18n (textdomain, msgid, params, 2));}/** * The same as the first method, just with only one * parameters. * Just for your convenience. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @param param Substitution string for $0. * @returns The translated string. */string I18N::i18n (const string &textdomain, const string &msgid, const string ¶m){ string params[] = { param }; return (I18N::i18n (textdomain, msgid, params, 1));}/** * The same as the first method, just with no * parameters. * Just for your convenience. * * @param textdomain The textdomain that should be used. * @param msgid The msgid that should be translated. * @returns The translated string. */string I18N::i18n (const string &textdomain, const string &msgid){ return (I18N::i18n (textdomain, msgid, NULL, 0));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -