build: download zh translation from emqx-i18n.git

This commit is contained in:
Zaiming (Stone) Shi 2023-05-29 14:06:23 +02:00
parent 7032881790
commit d014b80834
4 changed files with 23 additions and 38 deletions

View File

@ -27,15 +27,12 @@
%% @doc Global ETS table to cache the description of the configuration items. %% @doc Global ETS table to cache the description of the configuration items.
%% The table is owned by the emqx_dashboard_sup the root supervisor of emqx_dashboard. %% The table is owned by the emqx_dashboard_sup the root supervisor of emqx_dashboard.
%% The cache is initialized with the default language (English) and %% The cache is initialized with the default language (English) and
%% all the desc.<lang>.hocon files in the www/static directory (extracted from dashboard package). %% all the desc.<lang>.hocon files in the app's priv directory
init() -> init() ->
ok = ensure_app_loaded(emqx_dashboard), ok = ensure_app_loaded(emqx_dashboard),
PrivDir = code:priv_dir(emqx_dashboard), PrivDir = code:priv_dir(emqx_dashboard),
EngDesc = filename:join([PrivDir, "desc.en.hocon"]), Files0 = filelib:wildcard("desc.*.hocon", PrivDir),
WwwStaticDir = filename:join([PrivDir, "www", "static"]), Files = lists:map(fun(F) -> filename:join([PrivDir, F]) end, Files0),
OtherLangDesc0 = filelib:wildcard("desc.*.hocon", WwwStaticDir),
OtherLangDesc = lists:map(fun(F) -> filename:join([WwwStaticDir, F]) end, OtherLangDesc0),
Files = [EngDesc | OtherLangDesc],
ok = emqx_utils_ets:new(?MODULE, [public, ordered_set, {read_concurrency, true}]), ok = emqx_utils_ets:new(?MODULE, [public, ordered_set, {read_concurrency, true}]),
ok = lists:foreach(fun(F) -> load_desc(?MODULE, F) end, Files). ok = lists:foreach(fun(F) -> load_desc(?MODULE, F) end, Files).

View File

@ -82,7 +82,7 @@ check_license_watermark(Conf) ->
%% @doc The default license key. %% @doc The default license key.
%% This default license has 1000 connections limit. %% This default license has 1000 connections limit.
%% It is issued on 2023-01-09 and valid for 5 years (1825 days) %% It is issued on 2023-01-09 and valid for 5 years (1825 days)
%% NOTE: when updating a new key, the schema doc in emqx_license_schema_i18n.conf %% NOTE: when updating a new key, the schema doc in emqx_license_schema.hocon
%% should be updated accordingly %% should be updated accordingly
default_license() -> default_license() ->
<< <<

View File

@ -19,9 +19,7 @@ main(_) ->
io_lib:nl() io_lib:nl()
], ],
ok = file:write_file("apps/emqx_conf/etc/emqx.conf.all", Conf), ok = file:write_file("apps/emqx_conf/etc/emqx.conf.all", Conf),
merge_desc_files_per_lang("en"), merge_desc_files().
%% TODO: remove this when we have zh translation moved to dashboard package
merge_desc_files_per_lang("zh").
merge(BaseConf, Cfgs) -> merge(BaseConf, Cfgs) ->
Confs = [BaseConf | lists:map(fun read_conf/1, Cfgs)], Confs = [BaseConf | lists:map(fun read_conf/1, Cfgs)],
@ -80,29 +78,17 @@ try_enter_child(Dir, Files, Cfgs) ->
get_all_cfgs(filename:join([Dir, "src"]), Cfgs) get_all_cfgs(filename:join([Dir, "src"]), Cfgs)
end. end.
%% Desc files merge is for now done locally in emqx.git repo for all languages. %% Merge English descriptions.
%% When zh and other languages are moved to a separate repo, %% other translations are downloaded in pre-compile.sh
%% we will only merge the en files. merge_desc_files() ->
%% The file for other languages will be merged in the other repo,
%% the built as a part of the dashboard package,
%% finally got pulled at build time as a part of the dashboard package.
merge_desc_files_per_lang(Lang) ->
BaseConf = <<"">>, BaseConf = <<"">>,
Cfgs0 = get_all_desc_files(Lang), Cfgs0 = get_all_desc_files(),
Conf = do_merge_desc_files_per_lang(BaseConf, Cfgs0), Conf = do_merge_desc_files(BaseConf, Cfgs0),
OutputFile = case Lang of OutputFile = "apps/emqx_dashboard/priv/desc.en.hocon",
"en" ->
%% en desc will always be in the priv dir of emqx_dashboard
"apps/emqx_dashboard/priv/desc.en.hocon";
"zh" ->
%% so far we inject zh desc as if it's extracted from dashboard package
%% TODO: remove this when we have zh translation moved to dashboard package
"apps/emqx_dashboard/priv/www/static/desc.zh.hocon"
end,
ok = filelib:ensure_dir(OutputFile), ok = filelib:ensure_dir(OutputFile),
ok = file:write_file(OutputFile, Conf). ok = file:write_file(OutputFile, Conf).
do_merge_desc_files_per_lang(BaseConf, Cfgs) -> do_merge_desc_files(BaseConf, Cfgs) ->
lists:foldl( lists:foldl(
fun(CfgFile, Acc) -> fun(CfgFile, Acc) ->
case filelib:is_regular(CfgFile) of case filelib:is_regular(CfgFile) of
@ -113,14 +99,7 @@ do_merge_desc_files_per_lang(BaseConf, Cfgs) ->
end end
end, BaseConf, Cfgs). end, BaseConf, Cfgs).
get_all_desc_files(Lang) -> get_all_desc_files() ->
Dir = Dir = filename:join(["rel", "i18n"]),
case Lang of
"en" ->
filename:join(["rel", "i18n"]);
"zh" ->
%% TODO: remove this when we have zh translation moved to dashboard package
filename:join(["rel", "i18n", "zh"])
end,
Files = filelib:wildcard("*.hocon", Dir), Files = filelib:wildcard("*.hocon", Dir),
lists:map(fun(Name) -> filename:join([Dir, Name]) end, Files). lists:map(fun(Name) -> filename:join([Dir, Name]) end, Files).

View File

@ -19,5 +19,14 @@ esac
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.." cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
./scripts/get-dashboard.sh "$dashboard_version" ./scripts/get-dashboard.sh "$dashboard_version"
# generate merged config files and English translation of the desc (desc.en.hocon)
./scripts/merge-config.escript ./scripts/merge-config.escript
# 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'
# generate sbom
./scripts/update-bom.sh "$PROFILE_STR" ./rel ./scripts/update-bom.sh "$PROFILE_STR" ./rel