Symfony Twig Translation does not fill in placeholders - symfony

I am currently having the situation where a twig-filtered string that contains placeholders does only translate the string itself but does not respect the available, and linked, placeholders.
My example:
{{ 'this is my test: %test%'|trans({'%test%': 'test!'|trans}) }}
I have the translation available in my XLF file (automatically generated by symfony), lets say I add __ as prefixex to the string. I clear the cache and reload, and I do see that the string itself get translated, but now, instead of:
__this is my test: __test!
The string looks like this:
__this is my test: %test%
In other words, it does not seem to insert the placeholder as expected.
Why? The placeholder translation works however, if I remove the original translation for the parent string. So, only one does work:
translate the parent string
place the placeholder correctly
But not both at the same time.
The template where I am using this is included by another template. Is this maybe an issue?

Default engine of translator isn't enough smart to do it, and there is a lot of confusions with word between % like %test%. To translate sentences like yours, you should use the ICU format. Here is an article about the ICU format and Symfony
You can fix it in a few steps:
Surround the parameter with { } in the sentence to translate:
{{ 'this is my test: {test}'|trans({'test': 'test!'|trans}) }}
Tell to symfony your using the ICU format by adding the good extension on your translation file. As example, rename your file from messages.yaml to messages+intl-icu.en.yaml
Clear your cache
Report modifications to your messages+intl-icu.en.yaml file.
# translations/messages+intl-icu.en.yaml
test!: '__test!'
"this is my test: {test}": '__this is my test: {test}'
Be aware on the non-translated parameter in translated sentence! Keep in mind that {test} shall NOT be translated because it will be replace by value after the translation process.
In your code, the process is:
translate test! to __test!
translate this is my test: {test} to __this is my test: {test}
replace {test} by __test!
Result becomes like you expected it:
__this is my test: __test!

Related

Why fn:substring-after Xquery function could not be used inside ML TDE

In my ML db, we have documents with distributor code like 'DIST:5012' (DIST:XXXX) XXXX is a four-digit number.
currently, in my TDE, the below code works well.
However instead of concat all the raw distributor codes, I want to simply concat the number part only. I used the fn:substring-after XQuery function. However, it won't work. It won't show that distributorCode column in the SQL View anymore. (Below code does not work.)
What is wrong? How to fix that?
Both fn:substring-after and fn:string-join is in TDE Dialect page.
https://docs.marklogic.com/9.0/guide/app-dev/TDE#id_99178
substring-after() expects a single string as input, not a sequence of strings.
To demonstrate, this will not work:
let $dist := ("DIST:5012", "DIST:5013")
return substring-after($dist, "DIST:")
This will:
for $dist in ("DIST:5012", "DIST:5013")
return substring-after($dist, "DIST:")
I need to double check what XPath expressions will work in a DTE, you might be able to change it to apply the substring-after() function in the last step:
fn:string-join( distributors/distributor/urn/substring-after(., 'DIST:'), ';')

How to access map in template string?

I want to use values from gradle.properties that should go into a template string.
A naive first:
println("${project.properties[somekey]}")
doesn't work: Unresolved reference: somekey
So, quotes required?
println("${project.properties[\"somekey\"]}")
is completely broken syntax: Expecting an expression for the first .
I couldn't find any example how to do this, yet the official documentation says expressions.
Question: is it possible to access a map in string template, and if so, how?
Yes and as follows:
"${project.properties["someKey"]}"
assuming the Map has the following signature: Map<String, Any?> (or Map<Any...)
Alternatives:
"${project.properties.getValue("someKey")}"
"${project.properties.getOrElse("someKey") { "lazy-evaluation-default-value" }}"
"${project.properties.getOrDefault("someKey", "someFixedDefaultValue")}"
Basically all the code you put in the ${} is just plain Kotlin code... no further quoting/escaping required, except for the dollar sign $ itself, e.g. use "\$test" if you do not want it to be substituted with a variable named test or """${"$"}test""" if you use a raw string
Note that in this println case the following would have sufficed as well (which also goes for all the shown alternatives above. You may omit the outer surrounding quotes and ${} altogether):
println(project.properties["someKey"])
See also Basic types - String templates

Copy dictionary to register in Vim

I have a dictionary in my vimrc that I would like to copy and paste into whatever text file I'm editing:
let info = { 'tom':12345, 'bob':54689 }
I tried using put as I would with an option setting but I get an error:
:put=#info
How do I copy the contents of "info" to the register so that I can paste it in my text document?
If you want to maintain the exact representation, you have to store the dictionary as a string already (as per #sergio's answer), and you can :put it directly.
If it's fine to have Vim render the dictionary (and potentially reorder its elements), you just have to explicitly convert to a string, in order to overcome the E731: using Dictionary as a String (as it's :help explains, these types are not automatically converted). The string() function will do that:
:put =string(info)
Try quoting the json data. And removing # from put command (# is used to accessed registers, not for variables):
:let info="{ 'tom':12345, 'bob':54689 }"
:put=info

outputting text in XQuery using saxon9he: how do I get "<" and ">" created in the output themselves, not escaped?

My XQuery script:
declare namespace output = "http://​www.​w3.​org/​2010/​xslt-​xquery-​ser​iali​zati​on";
declare option output:method "text";
for $row in all/row
return ('"<row>","',data($row),'"
')
My XML:
<all>
<row>one</row>
<row>two</row>
<row>three</row>
</all>
My command line:
java -cp …/saxon9he.jar net.sf.saxon.Query '!omit-xml-declaration=yes' -s:./trouble-with-output-escaping.xml -q:./trouble-with-output-escaping.xqy
My output as created by saxon9he:
"<row>"," one "
"<row>"," two "
"<row>"," three "
I actually want to have output like this:
"<row>","one"
"<row>","two"
"<row>","three"
During my web investigation I came across XSLT's disable-output-escaping.
I thought: if XQuery had that, that might help.
Update/0:
Actually nothing (visible) was wrong with the above XQuery script.
The namespace declaration above needs to get replaced by this one:
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
Looks the same, but it isn't, as Michael pointed out.
Having completed this, the above is an example of how to create text output using XQuery.
In some other place Michael showed, how get rid of the space (0x20), that is being used to separate the lines, i.e. the space character preceding lines 2 to the end:
string-join(…,"")
where "…" would be the entire FLWOR.
It's doing the right thing if you set output method "text" from the command line, that is
java net.sf.saxon.Query -q:test.xquery -s:test.xml -t !method=text
but you had me baffled as to why setting the serialization options from within the query isn't working. Looking at it in the debugger, though, I see that your URI, which looks like
http://​www.​w3.​org/​2010/​xslt-​xquery-​ser​iali​zati​on
actually contains several occurrences of decimal 8203, hex 200B, which is a zero-width space. This means the URI doesn't match the serialization output URI, and "declare option" with an unrecognized URI is ignored.

Error while bootstrapping cloudify nodecellar example on localhost using virtualenv

executing bootstrap validation
Invalid input:
inputs.yaml. inputs must represent a dictionary.
Valid values can either be a path to a YAML file, a string formatted as YAML or a string formatted as key1=value1;key2=value2
How to solve this problem??
Since there are a lot of missing details in your question, I'll try to explain what could be the answer:
You didn't give the right path to the input.yaml file.
The path could be relative to your working directory, or a full path, but either way it must lead to the file.
Your input file is not formatted correctly.
An input.yaml file should include a dictionary of keys and values as in: image: 'redhat_santiago'. Tabs are not allowed, only spaces. All keys should be aligned to the same column.
Please try to check the above, in the future it would be better if you add the input file and the command you are using.
Best,
Jonathan

Resources