Escaping a pipe in a vue-i18n translation - vue.js

We need to have a translation in vue-i18n where the translated string have to contain a pipe character ( | ).
But in vue-i18n translation files, the pipe is used as delimiter for pluralization. We tried several ways to escape it (single or double backslash, etc.) but nothing worked…
I couldn’t find anything talking about that in vue-18n documentation.
I didn’t found issues talking about that in the vue-i18n github repository.
Is anybody has already faced it and found a workaround ?

Correct way to escape pipe & other special characters would be to use literal interpolation syntax.
"User profile {'|'} AppName"
https://vue-i18n.intlify.dev/guide/essentials/syntax.html#literal-interpolation

I understand the problematic.
You can solve your problem either by using $t instead of $tc, since $t method will not do a pluralization, or by putting pipe unicode: \u007C instead of | in your localization string.
Hope that any of these solutions will work for you. Cheers!

Related

Multi-line text in a .env file

In vue, is there a way to have a value span multiple lines in an .env file. Ex:
Instead of:
someValue=[{"someValue":"Here is a really really long piece which should be split into multiple lines"}]
I want to do something like:
someValue=`[{"someValue":"Here is a really
really long piece which
should be split into multiple lines"}]`
Doing the latter gives me a JSON parsing error if I try to do JSON.parse(someValue) in my code
I don't know if this will work, but I can't format a comment appropriately enough to get the point across so see if this will work:
someValue=[{"someValue":"Here is a really\
really long piece which\
should be split into multiple lines"}]
Where "\" should escape the newline similar to how you can write long bash commands while escaping the newline. I'm not certain the .env interpreter will support it though.
EDIT
Looks like this won't work. This syntax was actually proposed, but I don't think it was incorporated. See motdotla/dotenv#333 (which is what Vue uses to parse .env).
Like #zero298 said, this isn't possible. Likely you could delimit the entry with a character that wouldn't show up normally in the text (^ is a good candidate), then parse it within the application using string.replace('^', '\n');

BigQuery load - control character as delimiter

We have files to load where field values are separated by the "unit separator", 0x1f
As per the doc, if not printable, it should be encoded in UTF-8.
Using the bq CLI, I tried passing the -F argument with U+001F to no avail though:BigQuery error in load operation: Field delimiter must be a single character, found:"U+001F".
No luck either with 0x1F or `\x1f, with or without quotes.
Have I the encoding wrong or is it a bug in bq, or the API ?
EDIT:
Turns out after playing with the explorer that it's the API that doesn't like the delimiter.
Besides the printable delimiters, you can use \t but also the undocumented \b (backspace) and \f (form field) apparently.
tab could be a valid user-entered character in a free-form text field so we need to use a control char (after conversion from 'unit sep')
EDIT2::
Note that \f as delimiter does work fine through the API directly but not the bq CLI (Field delimiter must be a single character, found:"\f").
Actually, courtesy of GCP support, this works on Linux:
bq load --autodetect --field_delimiter=$(printf '\x1f') [DATASET].[TABLE] gs://[BUCKET]/simple.csv
On Windows, it's not that straightforward to return/generate a control character on the command-line. Easier if you use PowerShell.
I agree with #Felipe, this is currently a limitation in the bq CLI tool, but one that can easily be fixed in the source code in my mind with a .decode('utf-8') on the argument in bytes, so that
--field_delimiter=\x1f
can work as-is on any platform.
Closing with the hope the bq CLI team will consider the enhancement.
You can specify bq load --field_delimiter=$'\x01'
You found a limitation of the CLI: It won't accept all characters that the API would.
As said in edit2, the solution is to go straight to the API through alternative methods.

Perl 6: Backslashes in transliteration (tr///)

I noticed while experimenting with tr///, that it doesn't seem to translate backslashes, even when escaped. For example,
say TR"\^/v"." given 'v^/\\';
say TR"\\^/v"." given 'v^/\\';
say TR"\ ^/v"." given 'v^/\\';
All of them output ...\ rather than what I expected, ....
There's some other weird behaviour too, like \ seemingly only escaping lowercase letters, but the docs page doesn't have much information... What exactly is the behaviour of backslashes (\) in transliteration (tr///)?
There is a bug caused by backslashes getting swallowed instead of correctly escaping things in the grammar for tr///.
say TR/\\// given '\\'
===SORRY!=== Error while compiling:
Malformed replacement part; couldn't find final /
at line 2
------> <BOL>⏏<EOL>
I have raised https://github.com/rakudo/rakudo/issues/2456 and submitted https://github.com/rakudo/rakudo/pull/2457 which fixes it.
The second part of the answer is that Perl 6 tries quite hard in some quoting constructs to only interpret \ as an escape for valid escape sequences, i.e. \n, \r, \s, \', etc. Otherwise it is left as a literal \.
I do not have an explanation for the observed problem. However, when you use the Perl 6 Str.trans method it looks like it's working as expected:
say 'v^/\\'.trans( "\\^/v" => "." );
Outputs:
....
Reference:
https://perl6advent.wordpress.com/2010/12/21/day-21-transliteration-and-beyond/

Find and replace with variable

In webstorm 2017.1.1 I would like to find and replace a simple string with variable in the replace, for example:
find: testID:'
replace: testID:'${FILE_NAME}
And I expect the replace result will be testID:'MY_FILE_NAME...
Someone know if it's possible vie webstorm or via any plugin related?
Thanks in advance.
As #SupunWijerathne said, the IDEA replace dialogue is not aware of variables. However, this is something you could easily do in a shell. For example, on Linux, and with a replacement string without any special characters, you could do this:
sed -i "s/testID:'/testID:'${FILE_NAME}/g" my-file.txt

escaping xml in intellij 14

in Intellij, I'm looking for a single keystroke method to transform escaped XML to XML and vice versa I've looked at macros with a file find/replace but they are not doing what I need - any suggestions?
e.g.
<Alpha>
<Beta>3030</Beta>
<Beta>3030</Beta>
</Alpha>
TO
<Alpha>
<Beta>3030</Beta>
<Beta>3030</Beta>
</Alpha>
Take a look at this plugin, it can do what you want and much more in terms of escaping and string manipulation in general.
You can bind some custom shortcut to Escape XML and Unescape XML actions. Or you can hit SHIFT+ALT+M and then 8 to escape or SHIFT+ALT+M and then 9 to unescape by default.
It's probably not the exact solution you're looking for, but hopefully it will help.