build: generate desc.en.hocon file for i18n
This commit is contained in:
parent
aa4a2d9331
commit
5990f9835f
3
build
3
build
|
@ -133,6 +133,9 @@ make_docs() {
|
||||||
erl -noshell -eval \
|
erl -noshell -eval \
|
||||||
"ok = emqx_conf:dump_schema('$docdir', $SCHEMA_MODULE), \
|
"ok = emqx_conf:dump_schema('$docdir', $SCHEMA_MODULE), \
|
||||||
halt(0)."
|
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
|
## arg1 is the profile for which the following args (as app names) should be excluded
|
||||||
|
|
|
@ -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).
|
Loading…
Reference in New Issue