hi,
I just try to test localization flow of UE4, and find out this test case didn’t work:
FText MsgText1 = NSLOCTEXT("MyTestNamespace", "MsgText1", R"(test)");
FText MsgText2 = NSLOCTEXT("MyTestNamespace", "MsgText2", R"(<text color="#77FF77AA" shadowColor="#FF0000FF" shadowOffset="[4,3]" >test Raw string literal localization </text>)");
when I press “Gather Text” in Localization Dashboard, the result become like this:
MsgText1 is half gathered, and
MsgText2 is failed to be gathered and ignored.
It will be more convenience if UE4 can support this use case, because it will not need insert any ugly escaped character for the MsgText2. Like this one:
NSLOCTEXT("MyTestNamespace", "MsgText3", "<text color=\"#77FF77AA\" shadowColor=\"#FF0000FF\" shadowOffset=\"[4,3]\" >test localization </text>");
Hey dorgon-
The documentation for FTEXT (FText in Unreal Engine | Unreal Engine 5.1 Documentation), which shows an example of NSLOCKTEXT, shows that the namespace, key, and text must be enclosed in double quotes. It appears that the “R” in the code sample provided would cause compile errors. Can you explain exactly what you’re trying to do? If possible, please include steps to help me reproduce the issue on my end.
hi,
Thank you for your reply.
I just want to use C++11 feature call raw string literal that use “R” as syntax. You can find reference here:
http://en.cppreference.com/w/cpp/language/string_literal
My goal is trying to remove ugly escape character(backslash ‘’) in C++ code. Because this new C++11 feature is good at handle this situation, so I trying to use this syntax. All job are done perfectly until I trying to localize my text.
How do I reproduce this:
1.Create a C++ UE4 project using visual studio 2015 community
2.Add Following code to my player controller:
FText MsgText1 = NSLOCTEXT("MyTestNamespace", "MsgText1", R"(test)");
FText MsgText2 = NSLOCTEXT("MyTestNamespace", "MsgText2", R"(<text color="#77FF77AA" shadowColor="#FF0000FF" shadowOffset="[4,3]" >test Raw string literal localization </text>)");
3.Compile code and run editor
4.Editor preferences->Experimental-> Enable Localization Dashboard
5.Open Localization Dashboard, check Gather from Text Files and add a search Directories to Source.
6.Press Gather Text and press edit translations for culture.
7.See the result.
It appears that the syntax you’re trying to use is language level which we don’t have any control over. I was able to find 2 slightly altered versions of the code you’re using that still compile without the escape characters.
FText MsgText4 = NSLOCTEXT("MyTestNamespace", "MsgText4", "<text color=""#77FF77AA" "shadowColor=""#FF0000FF" "shadowOffset=""[4,3]" ">test localization </text>");
FText MsgText5 = NSLOCTEXT("MyTestNamespace", "MsgText5", "<text color=#77FF77AA shadowColor=#FF0000FF shadowOffset=[4,3] >test localization </text>");
With MsgText4 there are additional quotes around the setting names (text color / shadowColor / ShadowOffset). With MsgText5 there are no quotes within the string text. If these do not work for what you’re trying to do, then using the escape character would be the proper solution.
Cheers
hi,
Thank you for your reply.
Altered versions will fail when I try to parse the text using XmlParser.
Maybe escape character is only solution if I want to localize my project…