easy_localization - using new line - \n in a String - flutter

In my Flutter Project I'm using the package easy_localization (https://pub.dev/packages/easy_localization).
I wan't to use Strings like this: This is my Test String.\nIt is supposed to be separated by a new line!.
easy_localization is ignoring the \n and simply shows it as the characters \n and not doing a real new line. A flutter string usually knows what is meant by a \n and interpret it correct.
How do I archive that a \n still get's interpreted as a new line?
Edit:
My localization files are xml files that are kinda like this:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<my_string_key>This is my Test String.\nIt is ... by a new line!</my_string_key>
</root>
And I call it somewhere as tr("my_string_key")
Edit:
My Solution now is just that I created a file my_localizer.dart that only got this function:
String myTr(String key) { return tr(key).replaceAll("\\n", "\n"); }
I could import it at the files that I needed it and can use it exactly like the original tr():
myTr("my_string_key")

You can use the replaceAll method on the string to replace the \n with a newline character (\n) before passing it to the easy_localization package. Here's an example:
String myString = "This is my Test String.\nIt is supposed to be separated by a new line!";
String localizedString = AppLocalizations.of(context).tr(myString.replaceAll("\n", "\n"));
This will replace all instances of \n in the string with actual newline characters, so that the string will be displayed as intended when passed through the easy_localization package.

Related

Special character in key in the conf file for Internationlization in play framework

I am trying to use the Internationalization feature of the Play Framework.
It involves the creation of a new conf file for each language that we want to support. Example for french we create a messages.fr file in the conf folder.
Inside it we define key-values like this:
Hello.World = 'Bonjour le monde'
Now the issue is that I have lines that contain characters like "," and "(" and if these are included in the key then we get the error in parsing from the MessageApi
Example
Hello.(World) = 'Bonjour (le monde)'
Here the "(" before and after World is throwing an error while parsing.
Anyone having any idea how we could achieve this?
Try to escape these special characters:
Hello.\(World\) = 'Bonjour (le monde)'
Other examples:
string_one = String for translation 1
string_two = one + one \= two
# String key with spaces
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# Backslash in value should be escaped by another backslash
path=c:\\wiki\\ templates
Also, you can try to escape special characters by using Java Unicode:
Hello.\u0028World\u0029 = 'Bonjour (le monde)'
Reference - How to escape the equals sign in properties files

Backslash in string from standard input, no way to stripe it

I have a string that comes from the standard input in Xcode, using Swift. When I type in my string, I write something like this :
He told me "Hello maaan"
What I see when I print my message after putting a breakpoint is this :
"He told me \"Hello maaan""
Now, the quotes at the start and the end can be ignored, but what's that backslash? If I run this code in the console
po message.contains("\\")
it returns me false. The thing is that I need to run a regex on that string and the regex fails because of that \ char. What's the solution?
EDIT
If I transform my string to a NSString, the console prints this :
He told me "Hello maaan
In order for the compiler to ignore the quotation marks you'll need to add the backslashes before both.
So, you'll need to format your string as so:
var string = " He told me: \"Hello Man\"."
print(string)

can't get correct chinese character from " google::protobuf::TextFormat::PrintToString "

I was use the protobuf to read and write config file. but I found the chinese character can't correctly write to the file.
the encode code:
zrd::Config cfg;
zrd::Market *market = nullptr;
market = cfg.add_market();
market->set_id("11");
market->set_name("清江冷链市场");
market->set_district("六合区");
string content;
google::protobuf::TextFormat::PrintToString(cfg, &content);
when run finished , the content is like this:
market {\n id: \"11\"\n name: \"\346\270\205\346\261\237\345\206\267\351\223\276\345\270\202\345\234\272\"\n district: \"\345\205\255\345\220\210\345\214\272\"\n}
why the chinese character is convert to that way ? when I use ofstream to write the content to file, such chinese characters are not convenient to read. but the probobuf can decode it successfully.
I wonder know whether there is way to save the chinese characters in right way?

How can I save Perl/Expect output that contains mixed ascii content?

I have a perl script that uses the expect library to login to a remote system. I'm getting the final output of the interaction with the before method:
$exp->before();
I'm saving this to a text file. When I use cat on the file it outputs fine in the terminal, but when I open the text file in an editor or try to process it the formatting is bizarre:
[H[2J[1;19HCIRCULATION ACTIVITY by TERMINAL (Nov 6,14)[11;1H
Is there a better way to save the output?
When I run enca it's identified as:
7bit ASCII characters
Surrounded by/intermixed with non-text data
you can remove none ascii chars.
$str1 =~ s/[^[:ascii:]]//g;
print "$str1\n";
I was able to remove the ANSI escape codes from my output by using the Text::ANSI::Util library's ta_strip() function:
my $ansi_string = $exp->before();
my $clean_string = ta_strip($ansi_string);

Perl Net::Jabber::Bot new line

I'm using Net::Jabber::Bot module in my Perl script and it works properly but one problem is that when I want to send a message all new lines get removed! Two questions :
How we can have new lines in our messages? Should we disable achomp somewhere?
What happens with new lines in Jabber/XMPP?
This is a known issue, somebody already submitted a patch for this: http://code.google.com/p/perl-net-jabber-bot/issues/detail?id=24
You are not able to send \n directly but you maybe able to send xmpp/jabber coded newline if that code does not contain unprintable chars.
In this sub:
sub _send_individual_message {
...
# Strip out anything that's not a printable character
# Now with unicode support?
$message_chunk =~ s/[^[:print:]]+/./xmsg;