Difference between revisions of "Transform Framework"
(→Use the transform framework) |
(→Example: .loc files) |
||
Line 40: | Line 40: | ||
A supported file format that is close to this one is <code>properties</code>. |
A supported file format that is close to this one is <code>properties</code>. |
||
+ | == transform_from_repo.sh == |
||
− | == |
||
+ | An <i>example</i> snippet of bash code for this type of file may be something like: |
||
+ | <pre> |
||
+ | #!/bin/bash |
||
+ | |||
+ | # Find all the files ending in the 'input suffix' (e.g. resx) |
||
+ | find $CLIENT_SOURCE_DIR -name "*loc" > ~/tmp/input_files.txt |
||
+ | |||
+ | # Transform each .loc file into a .properties file |
||
+ | cat ~/tmp/input_files.txt | while read -r FILEPATH |
||
+ | do |
||
+ | FILENAME=`basename $FILEPATH` |
||
+ | DIRNAME=`dirname $FILEPATH` |
||
+ | file "$FILEPATH" |
||
+ | SUFFIX=".loc" |
||
+ | ROOTNAME=${FILEPATH%$SUFFIX} |
||
+ | TARGET="${ROOTNAME}.properties" |
||
+ | iconv -f UTF-16 -t UTF-8 -c "$FILEPATH" > "$TARGET" |
||
+ | sed -i 's/^#/# #/' "$TARGET" |
||
+ | sed -i 's/^;/# ;/' "$TARGET" |
||
+ | sed -i -e "s/[[:space:]]\+/=/" "$TARGET" |
||
+ | sed -i -e "s/^=$//" "$TARGET" |
||
+ | done |
||
+ | </pre> |
||
+ | |||
+ | == transform_to_repo.sh == |
||
+ | An <i>example</i> snippet of bash code for this type of file may be something like: |
||
+ | <pre> |
||
+ | #!/bin/bash |
||
+ | |||
+ | # Find all the files ending in the 'input suffix' (e.g. resx) |
||
+ | find $CLIENT_SOURCE_DIR -name "*.properties" > ~/tmp/input_files.txt |
||
+ | |||
+ | # |
||
+ | # Transform each .properties into a .loc |
||
+ | # |
||
+ | cat ~/tmp/input_files.txt | while read -r FILEPATH |
||
+ | do |
||
+ | FILENAME=`basename $FILEPATH` |
||
+ | DIRNAME=`dirname $FILEPATH` |
||
+ | ls -l "$FILEPATH" |
||
+ | SUFFIX=".properties" |
||
+ | ROOTNAME=${FILEPATH%$SUFFIX} |
||
+ | TARGET="${ROOTNAME}.loc" |
||
+ | cp "$FILEPATH" "$TARGET" |
||
+ | sed -i 's/^#=#/#/' "$TARGET" |
||
+ | sed -i 's/^#=;/;/' "$TARGET" |
||
+ | sed -i -e "s/^#\([[:alnum:]]*\)/;\1/" "$TARGET" |
||
+ | sed -i -e "s/\([[:alnum:]]*\)=/\1\t/" "$TARGET" |
||
+ | iconv -f UTF-8 -t UTF-16 -c "$TARGET" > tmp.tmp |
||
+ | mv tmp.tmp "$TARGET" |
||
+ | done |
||
+ | </pre> |
||
+ | |||
+ | == transform_files_list.sh == |
||
+ | An <i>example</i> snippet of bash code for this type of file may be something like: |
||
+ | <pre> |
||
+ | #!/bin/bash |
||
+ | # Check if there is a parameter |
||
+ | if [ -z "$1" ] |
||
+ | then |
||
+ | echo "Error: Missing the argument like /<path>/pseudo_files.txt" |
||
+ | exit 1 |
||
+ | fi |
||
+ | |||
+ | # If the file exists then do something, otherwise exit |
||
+ | if [ -f "$1" ]; then |
||
+ | echo " File to rewrite: $1" |
||
+ | else |
||
+ | echo " $1 not found" |
||
+ | exit 1 |
||
+ | fi |
||
+ | |||
+ | # Rename .properties to .loc files inside the list of files passed as a parameter |
||
+ | sed -i 's/\.properties/.loc/' "$1" |
||
+ | </pre> |
Revision as of 15:41, 24 April 2019
LRM supports a number of file types out of the box (See Supported Resource Bundles). However, other file types may represent user facing strings to be translated. In that case, some customization is required to on-board those projects. The bash script transform framework facilitates the customization.
Contents
Analyze the file types
If the file types fall into a category not supported by LRM out of the box, the first thing to do is to see what is the closest file types supported by LRM.
Use the transform framework
The transform framework needs three scripts in order to fit in with LRM. The three scripts need to be under the $JENKINS_HOME/lingoport/transform/<nameoftransform>/
directory.
The <nameoftransform> must be indicative of the type of transformation to apply. For instance, it could be loc
to handle .loc files (see below). In that case, three scripts will need to be under /var/lib/jenkins/lingoport/transform/loc
for a typical installation where the jenkins
user is under /var/lib/jenkins
.
The three scripts to write are:
- transform_from_repo.sh: How to transform the files from the repository so they fit into an LRM supported file type
- transform_to_repo.sh: How to transform translated/pseudo-localized files in an LRM supported file type into the repository file type
- transform_files_list.sh: How to transform the file names from the LRM supported file naming into the repository file naming
When those scripts are written, the transformation is defined in the config directory of the on-boarded project with the transform.properties
. This file contains one properties, 'transform'. For instance, if loc
is the directory with those three scripts under $JENKINS_HOME/lingoport/transform/
for a <PROJECT> under a <GROUP>, the file will be:
$JENKINS_HOME/Lingoport_Data/L10nStreamlining/<GROUP>/projects/<PROJECT>/config/transform.properties
transform=loc
Example: .loc files
Say the repository contains resource files like the following hmUiMessage.loc
file:
;hmUiMessage.loc ;********************************************************************* #include hmUiMain.loc ;********************************************************************* message1 The first message message2 The second message message3 The third message message4 The fourth message
The file may not be in ASCII or UTF-8 format; For instance this file is in UTF-16BE
A supported file format that is close to this one is properties
.
transform_from_repo.sh
An example snippet of bash code for this type of file may be something like:
#!/bin/bash # Find all the files ending in the 'input suffix' (e.g. resx) find $CLIENT_SOURCE_DIR -name "*loc" > ~/tmp/input_files.txt # Transform each .loc file into a .properties file cat ~/tmp/input_files.txt | while read -r FILEPATH do FILENAME=`basename $FILEPATH` DIRNAME=`dirname $FILEPATH` file "$FILEPATH" SUFFIX=".loc" ROOTNAME=${FILEPATH%$SUFFIX} TARGET="${ROOTNAME}.properties" iconv -f UTF-16 -t UTF-8 -c "$FILEPATH" > "$TARGET" sed -i 's/^#/# #/' "$TARGET" sed -i 's/^;/# ;/' "$TARGET" sed -i -e "s/[[:space:]]\+/=/" "$TARGET" sed -i -e "s/^=$//" "$TARGET" done
transform_to_repo.sh
An example snippet of bash code for this type of file may be something like:
#!/bin/bash # Find all the files ending in the 'input suffix' (e.g. resx) find $CLIENT_SOURCE_DIR -name "*.properties" > ~/tmp/input_files.txt # # Transform each .properties into a .loc # cat ~/tmp/input_files.txt | while read -r FILEPATH do FILENAME=`basename $FILEPATH` DIRNAME=`dirname $FILEPATH` ls -l "$FILEPATH" SUFFIX=".properties" ROOTNAME=${FILEPATH%$SUFFIX} TARGET="${ROOTNAME}.loc" cp "$FILEPATH" "$TARGET" sed -i 's/^#=#/#/' "$TARGET" sed -i 's/^#=;/;/' "$TARGET" sed -i -e "s/^#\([[:alnum:]]*\)/;\1/" "$TARGET" sed -i -e "s/\([[:alnum:]]*\)=/\1\t/" "$TARGET" iconv -f UTF-8 -t UTF-16 -c "$TARGET" > tmp.tmp mv tmp.tmp "$TARGET" done
transform_files_list.sh
An example snippet of bash code for this type of file may be something like:
#!/bin/bash # Check if there is a parameter if [ -z "$1" ] then echo "Error: Missing the argument like /<path>/pseudo_files.txt" exit 1 fi # If the file exists then do something, otherwise exit if [ -f "$1" ]; then echo " File to rewrite: $1" else echo " $1 not found" exit 1 fi # Rename .properties to .loc files inside the list of files passed as a parameter sed -i 's/\.properties/.loc/' "$1"