有效的语言环境名称 [英] Valid Locale Names

查看:75
本文介绍了有效的语言环境名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到有效的语言环境名称?

How do you find valid locale names?

我当前正在使用MAC OSX.
但是有关其他平台的信息也将很有用.

I am currently using MAC OS X.
But information about other platforms would also be useful.

#include <fstream>
#include <iostream>


int main(int argc,char* argv[])
{
    try
    {
        std::wifstream  data;
        data.imbue(std::locale("en_US.UTF-16"));
        data.open("Plop");
    }
    catch(std::exception const& e)
    {
        std::cout << "Exception: " << e.what() << "\n";
        throw;
    }
}

% g++ main.cpp
% ./a.out
Exception: locale::facet::_S_create_c_locale name not valid
Abort

推荐答案

此页面显示:

构造函数调用std :: locale(")创建一个代表用户首选项的语言环境对象.该标准没有说明这意味着什么,但是在许多系统上,该库代替了在环境变量(通常为LANGLC_ALL)中找到的所有内容,代替了空字符串.例如,美国语言环境的通用名称是"en_US". (在POSIX系统上,您可以键入locale -a列出受支持的语言环境的名称.)

The constructor call std::locale("") creates a locale object that represents the user's preferences. The standard doesn't say what this means, but on many systems the library substitutes whatever is found in an environment variable (often LANG or LC_ALL) in place of the empty string. A common name for the American locale, for example, is "en_US". (On POSIX systems you can type locale -a to list the names of supported locales.)

locale -a应该适合您.

如果您从C ++ std库以编程方式表示,我不确定.

If you mean programatically from the C++ std libary I'm not sure.

此堆栈溢出问题是也许也很相关,但他似乎反应不多.

This stack overflow question is probably also relevant, but he doesn't seem to have had much response.

修改

要使用UTF-16,您可能需要使用 libiconv ,如这个问题.

To use UTF-16 you probably will need to use libiconv as mentioned in this question.

这篇关于有效的语言环境名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆