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.
%% 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
%% 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() ->
ok = ensure_app_loaded(emqx_dashboard),
PrivDir = code:priv_dir(emqx_dashboard),
EngDesc = filename:join([PrivDir, "desc.en.hocon"]),
WwwStaticDir = filename:join([PrivDir, "www", "static"]),
OtherLangDesc0 = filelib:wildcard("desc.*.hocon", WwwStaticDir),
OtherLangDesc = lists:map(fun(F) -> filename:join([WwwStaticDir, F]) end, OtherLangDesc0),
Files = [EngDesc | OtherLangDesc],
Files0 = filelib:wildcard("desc.*.hocon", PrivDir),
Files = lists:map(fun(F) -> filename:join([PrivDir, F]) end, Files0),
ok = emqx_utils_ets:new(?MODULE, [public, ordered_set, {read_concurrency, true}]),
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.
%% This default license has 1000 connections limit.
%% 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
default_license() ->
<<

View File

@ -19,9 +19,7 @@ main(_) ->
io_lib:nl()
],
ok = file:write_file("apps/emqx_conf/etc/emqx.conf.all", Conf),
merge_desc_files_per_lang("en"),
%% TODO: remove this when we have zh translation moved to dashboard package
merge_desc_files_per_lang("zh").
merge_desc_files().
merge(BaseConf, 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)
end.
%% Desc files merge is for now done locally in emqx.git repo for all languages.
%% When zh and other languages are moved to a separate repo,
%% we will only merge the en 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) ->
%% Merge English descriptions.
%% other translations are downloaded in pre-compile.sh
merge_desc_files() ->
BaseConf = <<"">>,
Cfgs0 = get_all_desc_files(Lang),
Conf = do_merge_desc_files_per_lang(BaseConf, Cfgs0),
OutputFile = case Lang of
"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,
Cfgs0 = get_all_desc_files(),
Conf = do_merge_desc_files(BaseConf, Cfgs0),
OutputFile = "apps/emqx_dashboard/priv/desc.en.hocon",
ok = filelib:ensure_dir(OutputFile),
ok = file:write_file(OutputFile, Conf).
do_merge_desc_files_per_lang(BaseConf, Cfgs) ->
do_merge_desc_files(BaseConf, Cfgs) ->
lists:foldl(
fun(CfgFile, Acc) ->
case filelib:is_regular(CfgFile) of
@ -113,14 +99,7 @@ do_merge_desc_files_per_lang(BaseConf, Cfgs) ->
end
end, BaseConf, Cfgs).
get_all_desc_files(Lang) ->
Dir =
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,
get_all_desc_files() ->
Dir = filename:join(["rel", "i18n"]),
Files = filelib:wildcard("*.hocon", Dir),
lists:map(fun(Name) -> filename:join([Dir, Name]) end, Files).

View File

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