view libgui/languages/build_ts/update_ts_files @ 33608:5fba13104493 bytecode-interpreter tip

maint: merge default to bytecode-interpreter.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Sat, 18 May 2024 22:40:00 -0400
parents 5ce810c981ae
children
line wrap: on
line source

#!/bin/bash

# This scripts has to be called from the folder libgui/languages
# where the *.ts files for each provided translation are located

# The paths with libgui sources to scan for text strings
SEARCH_PATH_COMMON="../graphics ../qterminal ../src"

# Path to Qt and QScintilla files with strings that should also be
# translated by octave in case that Qt or QScintilla does not provide
# translations for the current language
SEARCH_PATH_QT="build_ts/octave-qt"
SEARCH_PATH_QSCI="build_ts/octave-qsci"

# The directory with translations provided by Qt and QScintilla
# FIXME: This constant should not be hardcoded.  Probably best if
# it could be picked up from the configuration such as HAVE_QTX in config.h.
QT_VERSION="qt5"
QT_LANG_DIR=/usr/share/$QT_VERSION/translations

# Now update all ts files
for file in $(ls -b1 *.ts)
do

  xx=${file:0:2}
  xx_yy=${file:0:5}

  # Set the search path to the minimal one used for each ts file
  SEARCH_PATH=$SEARCH_PATH_COMMON
  T_QT="YES"
  T_QSCI="YES"

  # Look for translations provided by Qt and QScintilla and extend the search
  # path if no existing translations are found. In this case we have to scan
  # the locally collected source files.
  if [ $xx_yy != "en_US" ]; then  # No translation required for en_US
    # Look for Qt translations
    if [ "`ls $QT_LANG_DIR | grep -i qt_$xx.qm | wc -l`" -eq 0 ] &&
       [ "`ls $QT_LANG_DIR | grep -i qt_$xx_yy.qm | wc -l`" -eq 0 ]; then
       SEARCH_PATH="$SEARCH_PATH $SEARCH_PATH_QT"
       T_QT="NO"
    fi
    # Look for QScintilla translations
    if [ "`ls $QT_LANG_DIR | grep -i qscintilla_$xx.qm | wc -l`" -eq 0 ] &&
       [ "`ls $QT_LANG_DIR | grep -i qscintilla_$xx_yy.qm | wc -l`" -eq 0 ]; then
       SEARCH_PATH="$SEARCH_PATH $SEARCH_PATH_QSCI"
       T_QSCI="NO"
    fi
  fi
  echo
  echo
  echo "$xx_yy: Existing translations for Qt: $T_QT, QSci: $T_QSCI"

  # Do the update after user's confirmation
  echo    "       => scan for strings in following paths"
  echo    "       => $SEARCH_PATH"
  read -p "       => Update (y/[n])? " ANS;
  ANS=${ANS:-n}
  if [ $ANS = "y" ]; then
    echo
    lupdate -$QT_VERSION -no-obsolete -locations relative $SEARCH_PATH -ts $file
  fi

done

echo