diff options
author | Barry Jackson <barjac@mageia.org> | 2023-01-22 17:52:11 +0000 |
---|---|---|
committer | Barry Jackson <barjac@mageia.org> | 2023-01-22 17:52:11 +0000 |
commit | db18acbd7b284307c6314a781e4044a1353e9379 (patch) | |
tree | ba85f2c98034defa74391b9da30f4fa90ecb9a43 /mk-pot | |
parent | 245bdbb90cb09b83f68cc7195b79c3685af0e3ce (diff) | |
download | remove-old-kernels-db18acbd7b284307c6314a781e4044a1353e9379.tar remove-old-kernels-db18acbd7b284307c6314a781e4044a1353e9379.tar.gz remove-old-kernels-db18acbd7b284307c6314a781e4044a1353e9379.tar.bz2 remove-old-kernels-db18acbd7b284307c6314a781e4044a1353e9379.tar.xz remove-old-kernels-db18acbd7b284307c6314a781e4044a1353e9379.zip |
- remove need for temp files
- parse script in one loop
Diffstat (limited to 'mk-pot')
-rwxr-xr-x | mk-pot | 95 |
1 files changed, 47 insertions, 48 deletions
@@ -1,63 +1,62 @@ #!/usr/bin/bash -# Create remove-old-kernels.pot from remove-old-kernels script +# Create remove-old-kernels.pot from remove-old-kernels bash script -# Get raw i18n strings (max two per script line) -while read line; do -if echo "$line"|grep -q '(i18n'; then - idstr1="$(echo "$line"|grep i18n|sed 's/\$(i18n/@/g'|cut -d@ -f2|cut -d\" -f2| sed 's/").*//')" - idstr2="$(echo "$line"|grep i18n|sed 's/\$(i18n/@/g'|cut -d@ -f3|cut -d\" -f2| sed 's/").*//')" - if [[ ${#idstr1} > 0 ]]; then - echo "$idstr1" >> pot-temp - if [[ ${#idstr2} > 0 ]]; then - echo "$idstr2" >> pot-temp - fi - fi -else - continue -fi -done < remove-old-kernels +# Path to output file +outpot=po/remove-old-kernels.pot -# Check for dupes -rawarray=(); x=0 ; y=0 -# Loop through pot-temp -while IFS= read -r line; do -# Reset isdupe - isdupe=0 +# Create new output file and add the default header +cat pot_header.txt > $outpot -#loop through array to check if msgid already exists +# Function to check found strings for duplicates +chk_dupe() { +# Loop through rawarray to check if msgid already exists (isdupe uses logical 0=true) +isdupe=1 for ((y=1;y<$((x+1));y++)); do - if [[ "$line" == "${rawarray[$y]}" ]]; then - isdupe=1 + if [[ "$1" == "${rawarray[$y]}" ]]; then + isdupe=0 break fi done - -# Dupe found so loop and ignore this $line - [[ $isdupe = 1 ]] && continue - -# Dupe not found so add string to array -# Increment line index + # Dupe not found so increment line index and add string to check array ((x++)) - rawarray[$x]="$line" - -# Output line to pot-temp2 - echo "msgid \""$line"\"" >> pot-temp2 - -# Insert blank msgstr line and blank line - echo -e 'msgstr ""\n' >> pot-temp2 -done < pot-temp - -echo "msgid's out: $x" + rawarray[$x]="$1" +return $isdupe +} -# Save to po dir -cat pot_header.txt > po/remove-old-kernels.pot -cat pot-temp2 >> po/remove-old-kernels.pot - -# Delete tmp files -rm -f pot-temp* +rawarray=(); x=0 ; y=0 +# Get raw i18n strings (max two per script line) +while IFS='' read -r line; do + if echo "$line"|grep -q '(i18n'; then +# [[ dbg -eq 1 ]] && echo "$line" + # Look for the first ocurrance of i18n and extract raw text only + idstr1="$(echo "$line"|grep i18n|sed "s/\$(i18n/@/g"|cut -d@ -f2|cut -d\" -f2| sed 's/").*//')" + isdupe=0 + # Check it is not dupe + if ! chk_dupe "$idstr1"; then + # Output line + IFS='' + echo -e "msgid \""$idstr1"\"\nmsgstr \"\"\n" >> $outpot + fi + # Look for a second ocurrance of i18n and extract raw text only + idstr2="$(echo "$line"|grep i18n|sed 's/\$(i18n/@/g'|cut -d@ -f3|cut -d\" -f2| sed 's/").*//')" + # Check it exists + if [[ ${#idstr2} > 0 ]]; then + isdupe=0 + # Check it is not dupe + if ! chk_dupe "$idstr2"; then + # Output line + IFS='' + echo -e "msgid \""$idstr2"\"\nmsgstr \"\"\n" >> $outpot + fi + fi +else + # Skip this script line + continue +fi +done < remove-old-kernels # Add date and time for last pot file change -sed -i "s/POT-Creation-Date: /&$(date '+%F %R%z')/" po/remove-old-kernels.pot +sed -i "s/POT-Creation-Date: /&$(date '+%F %R%z')/" $outpot # Update po files with any string changes from the pot file echo "Updating *.po files with any string changes" |