I make the internalization of a symfony2 site web, my code can generate unit translation like this:
<trans-unit id="861b143b00e2f350dfe22876922294066b160351" resname="utilisez.ff.chrome">
<source>utilisez.ff.chrome</source>
<target state="new">utilisez.ff.chrome</target>
<jms:reference-file line="85">Resources/views/base.html.twig</jms:reference-file>
<jms:reference-file line="62">Resources/views/base_jq.html.twig</jms:reference-file>
</trans-unit>
I have a csv file with data source;target (utilisez.ff.chrome; utilisez de préférence Firefox ou Chrome)
I would like to make a bash file which replace the target value with the value in the file. If you can help me it will be very nice :) I have little skills on bash command. thanks in advance.
Using xmlstarlet & xpath :
using the @id
:
xmlstarlet edit -L \
-u "//trans-unit[@id="861b143b00e2f350dfe22876922294066b160351"]/target/text()"\
-v 'utilisez de préférence Firefox ou Chrome' file.xml
or using text of the csv :
src="$(cut -d';' -f2 file.csv | tr -d $'\n')"
rep="$(cut -d';' -f3 file.csv | tr -d $'\n')"
xmlstarlet edit -L -u "//target/text()[@text()='$src'" -v "$rep" file.xml
<?xml version="1.0"?>
<trans-unit id="861b143b00e2f350dfe22876922294066b160351" resname="utilisez.ff.chrome">
<source>utilisez.ff.chrome</source>
<target state="new">utilisez de préférence Firefox ou Chrome</target>
<jms:reference-file line="85">Resources/views/base.html.twig</jms:reference-file>
<jms:reference-file line="62">Resources/views/base_jq.html.twig</jms:reference-file>
</trans-unit>