-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
3 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
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
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,50 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
|
||
message(STATUS "Verifying translation files...") | ||
file(GLOB_RECURSE TRANSLATIONS_FILES "*.lang.json") | ||
foreach(TRANSLATION_FILE ${TRANSLATIONS_FILES}) | ||
file(READ ${TRANSLATION_FILE} TRANSLATION_CONTENT) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-name\"" LANGUAGE_NAME_INDEX) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-native\"" LANGUAGE_NATIVE_INDEX) | ||
if (LANGUAGE_NAME_INDEX EQUAL -1 OR LANGUAGE_NATIVE_INDEX EQUAL -1) | ||
message(NOTICE "Translation file ${TRANSLATION_FILE} is missing 'language-name' or 'language-native' keys.") | ||
file(REMOVE ${TRANSLATION_FILE}) | ||
continue() | ||
endif() | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\"" LANGUAGE_CHARSET_INDEX) | ||
if (LANGUAGE_CHARSET_INDEX GREATER -1) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"default\"" LANGUAGE_CHARSET_DEFAULT) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"greek\"" LANGUAGE_CHARSET_GREEK) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"korean\"" LANGUAGE_CHARSET_KOREAN) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"japanese\"" LANGUAGE_CHARSET_JAPANESE) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"chinese-full\"" LANGUAGE_CHARSET_CHINESE_FULL) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"chinese-simplified\"" LANGUAGE_CHARSET_CHINESE_SIMPLIFIED) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"cyrillic\"" LANGUAGE_CHARSET_CYRILLIC) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"thai\"" LANGUAGE_CHARSET_THAI) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-charset\": \"vietnamese\"" LANGUAGE_CHARSET_VIETNAMESE) | ||
if (LANGUAGE_CHARSET_DEFAULT EQUAL -1 AND LANGUAGE_CHARSET_GREEK EQUAL -1 AND LANGUAGE_CHARSET_KOREAN EQUAL -1 AND LANGUAGE_CHARSET_JAPANESE EQUAL -1 AND LANGUAGE_CHARSET_CHINESE_FULL EQUAL -1 AND LANGUAGE_CHARSET_CHINESE_SIMPLIFIED EQUAL -1 AND LANGUAGE_CHARSET_CYRILLIC EQUAL -1 AND LANGUAGE_CHARSET_THAI EQUAL -1 AND LANGUAGE_CHARSET_VIETNAMESE EQUAL -1) | ||
message(NOTICE "Translation file ${TRANSLATION_FILE} has an invalid 'language-charset' value.") | ||
file(REMOVE ${TRANSLATION_FILE}) | ||
continue() | ||
endif() | ||
endif() | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-rtl\"" LANGUAGE_RTL_INDEX) | ||
if (LANGUAGE_RTL_INDEX GREATER -1) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-rtl\": true" LANGUAGE_RTL_TRUE) | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-rtl\": false" LANGUAGE_RTL_FALSE) | ||
if (LANGUAGE_RTL_TRUE EQUAL -1 AND LANGUAGE_RTL_FALSE EQUAL -1) | ||
message(NOTICE "Translation file ${TRANSLATION_FILE} has an invalid 'language-rtl' value.") | ||
file(REMOVE ${TRANSLATION_FILE}) | ||
continue() | ||
endif() | ||
endif() | ||
string(FIND ${TRANSLATION_CONTENT} "\"language-fallback\"" LANGUAGE_FALLBACK_INDEX) | ||
if (LANGUAGE_FALLBACK_INDEX GREATER -1) | ||
string(SUBSTRING ${TRANSLATION_CONTENT} ${LANGUAGE_FALLBACK_INDEX} 100 LANGUAGE_FALLBACK_STRING) | ||
string(REGEX REPLACE "\"language-fallback\": \"([a-zA-Z_]+)\".*" "\\1" LANGUAGE_FALLBACK_CODE ${LANGUAGE_FALLBACK_STRING}) | ||
if (NOT EXISTS "${LANGUAGE_FALLBACK_CODE}.lang.json") | ||
message(NOTICE "Translation file ${TRANSLATION_FILE} has 'language-fallback' value that doesn't exist: ${LANGUAGE_FALLBACK_CODE}.") | ||
file(REMOVE ${TRANSLATION_FILE}) | ||
endif() | ||
endif() | ||
endforeach() |
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,60 @@ | ||
#!/bin/bash | ||
# This script will generate a metadata.json file with the current timestamp and a list of all the languages available that pass the validation check | ||
|
||
function validate_json { | ||
jq empty $1 > /dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "Error: $1 is not a valid JSON file" | ||
return 1 | ||
fi | ||
|
||
jq -e 'has("language-name") and has("language-native")' $1 > /dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "Error: $1 is missing required fields" | ||
return 1 | ||
fi | ||
|
||
jq -e '.["language-name"] != "" and .["language-native"] != ""' $1 > /dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "Error: $1 has empty language-name or language-native" | ||
return 1 | ||
fi | ||
|
||
jq -e 'has("language-charset")' $1 > /dev/null | ||
if [ $? -eq 0 ]; then | ||
jq -e '.["language-charset"] | match("^(default|greek|korean|japanese|chinese-full|chinese-simplified|cyrillic|thai|vietnamese)$")' $1 > /dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "Error: $1 has an invalid language-charset" | ||
return 1 | ||
fi | ||
fi | ||
|
||
jq -e 'has("language-fallback")' $1 > /dev/null | ||
if [ $? -eq 0 ]; then | ||
fallback=$(jq -r '.["language-fallback"]' $1) | ||
if [ ! -f translations/$fallback.lang.json ]; then | ||
echo "Error: $1 has an invalid language-fallback" | ||
return 1 | ||
fi | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
TARGET_FILE=$1 | ||
rm -f $TARGET_FILE | ||
|
||
echo -n "{\"timestamp\": $(date +%s), \"languages\": [" > $TARGET_FILE | ||
|
||
for file in translations/*.lang.json; do | ||
validate_json $file | ||
if [ $? -ne 0 ]; then | ||
echo "Skipping $file" | ||
continue | ||
fi | ||
echo "Adding $(basename $file .lang.json) to metadata.json" | ||
echo -n "\"$(basename $file .lang.json)\"," >> $TARGET_FILE | ||
done | ||
|
||
sed -i '$ s/.$//' $TARGET_FILE | ||
echo -n "]}" >> $TARGET_FILE |