Skip to content

Commit

Permalink
pkp#8081 Added locale validation (detects bad syntax and finds duplic…
Browse files Browse the repository at this point in the history
…ated locale keys in a given language)
  • Loading branch information
jonasraoni committed Jul 11, 2022
1 parent 09ea1a2 commit cf59180
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tools/travis/validate-locale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# @file tools/travis/validate-json.sh
#
# Copyright (c) 2014-2021 Simon Fraser University
# Copyright (c) 2010-2021 John Willinsky
# Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
#
# Script to validate all JSON files in the repository (unless excluded).
#

set -e # Fail on first error

# Collects all languages
declare -A LANGUAGES=()
for LANGUAGE in lib/pkp/locale/* lib/pkp/plugins/*/*/locale/* locale/* plugins/*/*/locale/*; do
LANGUAGES[$(basename $LANGUAGE)]=1
done
LANGUAGE_SET=${!LANGUAGES[*]}

for LANGUAGE in $LANGUAGE_SET; do
# Look for syntax issues in the locale files
echo "Validating the syntax for the $LANGUAGE locale files..."
find lib/pkp/locale lib/pkp/plugins/*/*/locale locale plugins/*/*/locale -type f -path "*/$LANGUAGE/*.po" -print0 | xargs -0 -n1 msgfmt -c

# Look for duplicated locale entries
echo "Searching for duplicated locale keys in the language $LANGUAGE..."
readarray -d '' FILES < <(find lib/pkp/locale lib/pkp/plugins/*/*/locale -type f -path "*/$LANGUAGE/*.po" -print0)
if [ ${#FILES[@]} -gt 1 ]
then
OUTPUT=$(msgcomm --add-location --no-wrap --omit-header --more-than=1 ${FILES[@]})
if [ ${#OUTPUT} -gt 0 ]
then
echo -e "Found duplicated locale key:\n$OUTPUT"
exit 1
fi
fi
break
done

0 comments on commit cf59180

Please sign in to comment.