xml*_*lmx 8 c++ locale internationalization facet c++11
C++标准定义了六个类别方面的:collate,ctype,monetary,numeric,time,和messages.
我已经知道了前五个的用法,但我不知道何时以及如何使用最后一个:std::locale::messages.
任何说明性例子?
std::locale::messages用于打开消息目录(最常见的GNU gettext),包括翻译的字符串.下面是一个示例,它使用Linux(for sed)在德语中打开现有消息目录,检索(使用get())并输出英语字符串的翻译:
#include <iostream>
#include <locale>
int main()
{
std::locale loc("de_DE.utf8");
std::cout.imbue(loc);
auto& facet = std::use_facet<std::messages<char>>(loc);
auto cat = facet.open("sed", loc);
if(cat < 0 )
std::cout << "Could not open german \"sed\" message catalog\n";
else
std::cout << "\"No match\" in German: "
<< facet.get(cat, 0, 0, "No match") << '\n'
<< "\"Memory exhausted\" in German: "
<< facet.get(cat, 0, 0, "Memory exhausted") << '\n';
facet.close(cat);
}
Run Code Online (Sandbox Code Playgroud)
哪个输出:
"No match" in German: Keine Übereinstimmung
"Memory exhausted" in German: Speicher erschöpft
Run Code Online (Sandbox Code Playgroud)
编辑:根据此评论澄清.
| 归档时间: |
|
| 查看次数: |
2313 次 |
| 最近记录: |