File indexing completed on 2024-04-14 04:51:36

0001 #!/usr/bin/env bash
0002 
0003 # The name of catalog we create (without the.pot extension), sourced from the scripty scripts
0004 FILENAME="kdeconnect-android"
0005 
0006 function export_pot_file # First parameter will be the path of the pot file we have to create, includes $FILENAME
0007 {
0008         potfile=$1
0009         mkdir outdir
0010         ANSI_COLORS_DISABLED=1 a2po export --android res/ --gettext outdir
0011         mv outdir/template.pot $potfile
0012         rm -rf outdir
0013 }
0014 
0015 function import_po_files # First parameter will be a path that will contain several .po files with the format LANG.po
0016 {
0017         podir=$1
0018         # Android doesn't support languages with an @
0019         find "$podir" -type f -name "*@*.po" -delete
0020         # drop obsolete messages, as Babel cannot parse them -- see:
0021         # https://github.com/python-babel/babel/issues/206
0022         # https://github.com/python-babel/babel/issues/566
0023         find "$podir" -name '*.po' -exec msgattrib --no-obsolete -o {} {} \;
0024         ANSI_COLORS_DISABLED=1 a2po import --ignore-fuzzy --android res/ --gettext $podir
0025 
0026         # Generate the locales_config.xml
0027         pushd res
0028         echo '<?xml version="1.0" encoding="utf-8"?>' > xml/locales_config.xml
0029         echo '<locale-config xmlns:android="http://schemas.android.com/apk/res/android">' >> xml/locales_config.xml
0030         transform_locale_regex='(\w+)-r(\w+)'
0031         # Add en-US as the first locale so that is the fallback, and also because it won't be handled in the following loop
0032         echo -e '\t<locale android:name="en-US"/>' >> xml/locales_config.xml
0033         for i in values-*; do
0034                 if [ -d "${i}" ]; then
0035                         if [ -e "${i}/strings.xml" ]; then
0036                                 locale="${i:7}"
0037                                 if [[ "${locale}" =~ $transform_locale_regex ]]; then
0038                                         # Special case to turn locales like "en-rUS", "en-rGB" into "en-US" and "en-GB"
0039                                         transformed_locale="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}"
0040                                         echo -e "\t<locale android:name=\"${transformed_locale}\"/>" >> xml/locales_config.xml
0041                                 else
0042                                         echo -e "\t<locale android:name=\"${locale}\"/>" >> xml/locales_config.xml
0043                                 fi
0044                         fi
0045                 fi
0046         done
0047 
0048         echo "</locale-config>" >> xml/locales_config.xml
0049         popd
0050 }
0051