From aa4a2d93310b3df451b42a7d8ed1f6f82fd372ad Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 9 Nov 2023 16:25:55 +0100 Subject: [PATCH 1/3] build: start versioning i18n files --- scripts/pre-compile.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/pre-compile.sh b/scripts/pre-compile.sh index 632aabfe4..dfad7c869 100755 --- a/scripts/pre-compile.sh +++ b/scripts/pre-compile.sh @@ -25,10 +25,12 @@ cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.." # generate merged config files and English translation of the desc (desc.en.hocon) ./scripts/merge-config.escript +I18N_REPO_BRANCH="v$(./pkg-vsn.sh "${PROFILE_STR}" | tr -d '.' | cut -c 1-2)" + # download desc (i18n) translations curl -L --silent --show-error \ --output "apps/emqx_dashboard/priv/desc.zh.hocon" \ - 'https://raw.githubusercontent.com/emqx/emqx-i18n/main/desc.zh.hocon' + "https://raw.githubusercontent.com/emqx/emqx-i18n/${I18N_REPO_BRANCH}/desc.zh.hocon" # TODO # make sbom a build artifcat From 5990f9835fac9f2aa182721ecedb4c8c2c6b4595 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 9 Nov 2023 16:44:14 +0100 Subject: [PATCH 2/3] build: generate desc.en.hocon file for i18n --- build | 3 +++ scripts/merge-i18n.escript | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 scripts/merge-i18n.escript diff --git a/build b/build index 8b485f3b6..3ca5dfcec 100755 --- a/build +++ b/build @@ -133,6 +133,9 @@ make_docs() { erl -noshell -eval \ "ok = emqx_conf:dump_schema('$docdir', $SCHEMA_MODULE), \ halt(0)." + local desc="$docdir/desc.en.hocon" + log "Generating $desc" + scripts/merge-i18n.escript | jq --sort-keys . > "$desc" } ## arg1 is the profile for which the following args (as app names) should be excluded diff --git a/scripts/merge-i18n.escript b/scripts/merge-i18n.escript new file mode 100755 index 000000000..dfd76f01f --- /dev/null +++ b/scripts/merge-i18n.escript @@ -0,0 +1,41 @@ +#!/usr/bin/env escript + +%% This script is only used at build time to generate the merged desc.en.hocon in JSON format +%% but NOT the file generated to _build/$PROFILE/lib/emqx_dashboard/priv (which is HOCON format). +%% +%% The generated JSON file is used as the source of truth when translating to other languages. + +-mode(compile). + +-define(RED, "\e[31m"). +-define(RESET, "\e[39m"). + +main(_) -> + try + _ = hocon:module_info() + catch + _:_ -> + fail("hocon module not found, please make sure the project is compiled") + end, + %% wildcard all .hocon files in rel/i18n + Files = filelib:wildcard("rel/i18n/*.hocon"), + case Files of + [_ | _] -> + ok; + [] -> + fail("No .hocon files found in rel/i18n") + end, + case hocon:files(Files) of + {ok, Map} -> + JSON = jiffy:encode(Map), + io:format("~s~n", [JSON]); + {error, Reason} -> + fail("~p~n", [Reason]) + end. + +fail(Str) -> + fail(Str, []). + +fail(Str, Args) -> + io:format(standard_error, ?RED ++ "ERROR: " ++ Str ++ ?RESET ++ "~n", Args), + halt(1). From fd205f599c8e60739a8a693632df612bdb2f82c8 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 9 Nov 2023 18:14:56 +0100 Subject: [PATCH 3/3] build: do not generate desc.en.hocon if jq command is not found --- build | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/build b/build index 3ca5dfcec..c70f91b60 100755 --- a/build +++ b/build @@ -12,6 +12,12 @@ if [ "${DEBUG:-0}" -eq 1 ]; then export DIAGNOSTIC=1 fi +log_red() { + local RED='\033[0;31m' # Red + local NC='\033[0m' # No Color + echo -e "${RED}${1}${NC}" +} + PROFILE_ARG="$1" ARTIFACT="$2" @@ -34,7 +40,7 @@ case "$(is_enterprise "$PROFILE_ARG"),$(is_enterprise "$PROFILE_ENV")" in true ;; *) - echo "PROFILE env var is set to '$PROFILE_ENV', but '$0' arg1 is '$PROFILE_ARG'" + log_red "PROFILE env var is set to '$PROFILE_ENV', but '$0' arg1 is '$PROFILE_ARG'" exit 1 ;; esac @@ -134,8 +140,13 @@ make_docs() { "ok = emqx_conf:dump_schema('$docdir', $SCHEMA_MODULE), \ halt(0)." local desc="$docdir/desc.en.hocon" - log "Generating $desc" - scripts/merge-i18n.escript | jq --sort-keys . > "$desc" + if command -v jq &> /dev/null; then + log "Generating $desc" + scripts/merge-i18n.escript | jq --sort-keys . > "$desc" + else + # it is not a big deal if we cannot generate the desc + log_red "NOT Generated: $desc" + fi } ## arg1 is the profile for which the following args (as app names) should be excluded @@ -152,8 +163,8 @@ assert_no_excluded_deps() { for app in "${excluded_apps[@]}"; do found="$($FIND "$rel_dir" -maxdepth 1 -type d -name "$app-*")" if [ -n "${found}" ]; then - echo "ERROR: ${app} should not be included in ${PROFILE}" - echo "ERROR: found ${app} in ${rel_dir}" + log_red "ERROR: ${app} should not be included in ${PROFILE}" + log_red "ERROR: found ${app} in ${rel_dir}" exit 1 fi done @@ -294,7 +305,7 @@ make_tgz() { mkdir -p "${tard}/emqx" mkdir -p "${pkgpath}" if [ ! -f "$src_tarball" ]; then - log "ERROR: $src_tarball is not found" + log_red "ERROR: $src_tarball is not found" fi $TAR zxf "${src_tarball}" -C "${tard}/emqx" if [ -f "${tard}/emqx/releases/${PKG_VSN}/relup" ]; then