Project

General

Profile

Does Wt give some multilingual support

Added by ruliang ge almost 14 years ago

Hi,

I'm from China.

Does Wt give some multilingual support?

Such as Simplified Chinese or Japanese?

Can I use widget like WText to add a Chinese text?

Thank you!

Regards,

Ruliang


Replies (7)

RE: Does Wt give some multilingual support - Added by Wim Dumon almost 14 years ago

Hi Ruliang,

That is no problem, Wt works internally with UTF-8 strings and is therefore capable of representing chinese characters.

So how can you get your chinese in your WText? There's a number of ways (just giving a few here):

(1) Use our message resource bundle system (recommended for string literals)

This is what you often see in our examples. See WApplication::messageResourceBundle(), WWidget::tr(), WApplication::locale(), ... The chinese text is stored in an external XML file in UTF-8 format.

(2) Construct a WString from a UTF-8 string and pass it to the WText (recommended for all other cases):

Use WString::fromUTF8(): myText->setText(WString::fromUTF8(stringThatComesFromDatabase));

Use this method if your string was already available as UTF-8 text

(3) String literals in your C file (not recommended):

Use wchar_t strings in C to represent your chinese characters: myText->setText(L"put chinese characters here"); It cannot be guaranteed that this is portable.

Note that you can pass a c std::locale to the WString constructors to specify the locale of a char*, which Wt then uses to convert to UTF-8.

Regards,

Wim.

RE: Does Wt give some multilingual support - Added by Sergey Bryukov over 13 years ago

Then, how to correctly switch locale? Server is Ubuntu.

The code below:

std::cout<<env.locale()<<std::endl;

setLocale("ru_RU.UTF-8");

std::cout<<env.locale()<<std::endl;

gives me:

en-us

en-us

RE: Does Wt give some multilingual support - Added by Wim Dumon over 13 years ago

wApp->setLocale("ru-RU");

WEnvironment::locale() returns the language that the browser requests, so it will not be changed as consequence of calling WApplication::setLocale().

BR,

Wim.

RE: Does Wt give some multilingual support - Added by Sergey Bryukov over 13 years ago

The problematic with SuggestionPopup

I receive std::string from Google Geocoder through JSignalstd::string, then Im trying to add it as a suggestion sp_->addSuggestion(str,str);

I case of str contains Cyrillic I have Wt message: [error] "WString::widen(): could not widen string: Москва"

By the way, str is printable with std::cout. Sure, when str is English, SuggestionPupup works fine.

RE: Does Wt give some multilingual support - Added by Wim Dumon over 13 years ago

setLocale() is only used for translations (= which message resource bundles will be considered), not for character encoding.

You have to establish the character encoding from that std::string and use the proper method to construct a WString from it. As it comes from the browser, I strongly syspect it to be a UTF-8 string. In that case, you should convert it to a WString by using WString::fromUTF8(...).

Wim.

RE: Does Wt give some multilingual support - Added by Sergey Bryukov over 13 years ago

Wim,

I do have two message files for different language

At the session initiation I apply for one of them:

appInstance_->messageResourceBundle().use("messages_ru");

Late, as user clicked lang ico, I change message file:

appInstance_->messageResourceBundle().use("messages_en");

It seams message file doesn't changed and all messages are from messages_ru.xml

How to flush previously loaded message file?

RE: Does Wt give some multilingual support - Added by Koen Deforche over 13 years ago

Hey,

You should make this work like this:

Have your two files:

  messages.xml
  messages_ru.xml

These files will be part of the same message resource bundle:

appInstance_->messageResourceBundle().use("messages");

Then, use setLocale() to configure which one should be used:

setLocale("") or setLocale("en"): messages.xml

setLocale("ru"): messages_ru.xml

So in your lang icon, you should be calling setLocale() instead of appInstance_->messageResourceBundle().use("messages_en");

Regards,

koen

    (1-7/7)