forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#8081 Added locale validation (detects bad syntax and finds duplic…
…ated locale keys in a given language)
- Loading branch information
1 parent
09ea1a2
commit cf59180
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |