Difference between revisions of "Transform Framework"
(→Bash Variables) |
(→Example: .loc files) |
||
Line 31: | Line 31: | ||
* '''FULL_LIST_PATH''' : The list of all the files to be transformed from the translated files back to the repository |
* '''FULL_LIST_PATH''' : The list of all the files to be transformed from the translated files back to the repository |
||
− | == Example: |
+ | == Example: txt2propfiles == |
+ | |||
− | Say the repository contains resource files like the following <code>hmUiMessage.loc</code> file: |
||
+ | |||
+ | Say the repository contains resource files like the following <code>strings.txt</code> file: |
||
<pre> |
<pre> |
||
+ | # Strings for use in GUI |
||
− | ;hmUiMessage.loc |
||
+ | ################################################# |
||
− | ;********************************************************************* |
||
+ | PushIfCommits,Push if commits |
||
− | #include hmUiMain.loc |
||
+ | CloseButtonText,Close |
||
− | ;********************************************************************* |
||
+ | ApplyButtonText,Apply |
||
− | message1 The first message |
||
+ | CancelButtonText,Cancel |
||
− | message2 The second message |
||
− | message3 The third message |
||
− | message4 The fourth message |
||
</pre> |
</pre> |
||
− | The file may not be in ASCII |
+ | The file may not be in ASCII, UTF format, etc.; For instance this file is in UTF-8 |
− | 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>. So the transform script will change the file name, extension, and content, so as to be a standard resource file: |
+ | |||
+ | <code>strings.properties</code> |
||
+ | <pre> |
||
+ | # Strings for use in GUI |
||
+ | ################################################# |
||
+ | PushIfCommits=Push if commits |
||
+ | CloseButtonText=Close |
||
+ | ApplyButtonText=Apply |
||
+ | CancelButtonText=Cancel |
||
+ | </pre> |
||
== transform_from_repo.sh == |
== transform_from_repo.sh == |
Revision as of 17:15, 27 June 2024
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. The three scripts need to be in a repository, under a directory whose name will be used to identify the transform.
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
Each script can in turn call other scripts as necessary.
For example, under
- https://github.com/Lingoport/CommandCenterConfig, the main branch
a number of transform directories indicate what transform are available, in other words, what directories have those three scripts.
For example, for the txt2prop
transform, the directory is located :
Bash Variables
A few Bash variables are available when called from the Lingoport Jenkins jobs that use the transform framework. They are set before calling the transform framework.
- TRANSFORM_DIR : The transform scripts directory where the scripts are executed from.
- PROJECT_TMP_DIR : Where temporary files can be stashed for this project during the script execution
- FULL_LIST_PATH : The list of all the files to be transformed from the translated files back to the repository
Example: txt2propfiles
Say the repository contains resource files like the following strings.txt
file:
# Strings for use in GUI ################################################# PushIfCommits,Push if commits CloseButtonText,Close ApplyButtonText,Apply CancelButtonText,Cancel
The file may not be in ASCII, UTF format, etc.; For instance this file is in UTF-8
A supported file format that is close to this one is properties
. So the transform script will change the file name, extension, and content, so as to be a standard resource file:
strings.properties
# Strings for use in GUI ################################################# PushIfCommits=Push if commits CloseButtonText=Close ApplyButtonText=Apply CancelButtonText=Cancel
transform_from_repo.sh
An example snippet of bash code for this type of file may be something like:
#!/bin/bash echo "Transform loc files into .properties files" # Find all the files ending in 'loc' 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" echo "[${FILENAME}] -> [${TARGET}]" cp "$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 .properties find $CLIENT_SOURCE_DIR -name "*.properties" > ~/tmp/input_files.txt # echo "Transform .properties files into .loc files" # 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" echo "[${FILENAME}] -> [${TARGET}]" 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" 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"