如何将 SAPI 的 MS LANG ID 转换为 BCP 47 语言标签? [英] how to convert SAPI's MS LANG ID to BCP 47 language tag?

查看:15
本文介绍了如何将 SAPI 的 MS LANG ID 转换为 BCP 47 语言标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对 SAPI 的 get language 方法的调用返回一个 MS LangID,但出于我的目的,它需要转换为 BCP 47 语言标记(例如 en-GB).我们该怎么做呢?

The call to SAPI's get language method returns an MS LangID, but for my purpose, it needs to be converted to a BCP 47 language tag (eg. en-GB) . how do we do it?

我无法使用 LCIDToLocalName,为了使用这个函数,我需要先将返回值转换成LCID格式.

I am not able to do it using LCIDToLocalName, as to use this function, I need to convert the returned value into the LCID format first.

例如,它返回809"英语,现在我如何将其转换为LCID,因为英语的LCIDHex是0809",而LCIDec是2057".

For eg, it returns "809" for english, now how do I convert it into LCID first, as LCIDHex for English is "0809", and LCIDec is "2057".

任何帮助将不胜感激.

以下是代码

if (S_OK != SpEnumTokens(SPCAT_VOICES, NULL, NULL, &voice_tokens))
    return FALSE;

unsigned long voice_count, i = 0;
hr = voice_tokens->GetCount(&voice_count);
cout << " count " << voice_count << endl;
for (unsigned int i = 0; i < voice_count; i++){
    //cout << i << endl;
    CComPtr<ISpObjectToken> voice_token;
    if (S_OK != voice_tokens->Next(1, &voice_token, NULL))
        return FALSE;

    WCHAR *description;
    if (S_OK != SpGetDescription(voice_token, &description))
        return FALSE;


    CComPtr<ISpDataKey> attributes;
    if (S_OK != voice_token->OpenKey(kAttributesKey, &attributes))
        return FALSE;

    WCHAR *gender_s;
    TtsGenderType gender;
    if (S_OK == attributes->GetStringValue(kGenderValue, &gender_s)){
        if (0 == _wcsicmp(gender_s, L"male"))
            gender = TTS_GENDER_MALE;
        else if (0 == _wcsicmp(gender_s, L"female"))
            gender = TTS_GENDER_FEMALE;
    }


    WCHAR *language;
    if (S_OK != attributes->GetStringValue(kLanguageValue, &language))
        return FALSE;

    wprintf(L"%s\n", language);

最后一行打印 409 和 809 等十六进制值,但我希望它采用 En-US 之类的格式.

The last line prints hex values such as 409 and 809, but I want it in format like En-US .

推荐答案

@HansPassant 是正确的.你有一个字符串;将其解析为十六进制.使用 _wtoi(或您最喜欢的解析器),然后传递给 LCIDToLocaleName.

@HansPassant is correct. You've got a string; parse it as hex. Use _wtoi (or your favorite parser), then pass to LCIDToLocaleName.

对于 XP,您可以使用 DownlevelLCIDToLocaleName;所需的 DLL 可从 Microsoft 下载中心下载.

For XP, you can use DownlevelLCIDToLocaleName; the required DLL is downloadable from the Microsoft Download Center.

这篇关于如何将 SAPI 的 MS LANG ID 转换为 BCP 47 语言标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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