feat: move *i18n.conf from etc to i18n dir
This commit is contained in:
parent
630cc8ee34
commit
700c2cfb39
|
@ -1,4 +1,5 @@
|
||||||
.eunit
|
.eunit
|
||||||
|
*.conf.all
|
||||||
test-data/
|
test-data/
|
||||||
deps
|
deps
|
||||||
!deps/.placeholder
|
!deps/.placeholder
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
-export([update/3, update/4]).
|
-export([update/3, update/4]).
|
||||||
-export([remove/2, remove/3]).
|
-export([remove/2, remove/3]).
|
||||||
-export([reset/2, reset/3]).
|
-export([reset/2, reset/3]).
|
||||||
-export([dump_schema/1, dump_schema/2]).
|
-export([dump_schema/1, dump_schema/3]).
|
||||||
-export([schema_module/0]).
|
-export([schema_module/0]).
|
||||||
|
|
||||||
%% for rpc
|
%% for rpc
|
||||||
|
@ -133,41 +133,41 @@ reset(Node, KeyPath, Opts) ->
|
||||||
%% @doc Called from build script.
|
%% @doc Called from build script.
|
||||||
-spec dump_schema(file:name_all()) -> ok.
|
-spec dump_schema(file:name_all()) -> ok.
|
||||||
dump_schema(Dir) ->
|
dump_schema(Dir) ->
|
||||||
dump_schema(Dir, emqx_conf_schema).
|
I18nFile = emqx:etc_file("i18n.conf"),
|
||||||
|
dump_schema(Dir, emqx_conf_schema, I18nFile).
|
||||||
|
|
||||||
dump_schema(Dir, SchemaModule) ->
|
dump_schema(Dir, SchemaModule, I18nFile) ->
|
||||||
PrivDir = filename:dirname(filename:dirname(Dir)),
|
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Lang) ->
|
fun(Lang) ->
|
||||||
gen_config_md(Dir, PrivDir, SchemaModule, Lang),
|
gen_config_md(Dir, I18nFile, SchemaModule, Lang),
|
||||||
gen_hot_conf_schema_json(Dir, PrivDir, Lang)
|
gen_hot_conf_schema_json(Dir, I18nFile, Lang)
|
||||||
end,
|
end,
|
||||||
[en, zh]
|
[en, zh]
|
||||||
),
|
),
|
||||||
gen_schema_json(Dir, PrivDir, SchemaModule).
|
gen_schema_json(Dir, I18nFile, SchemaModule).
|
||||||
|
|
||||||
%% for scripts/spellcheck.
|
%% for scripts/spellcheck.
|
||||||
gen_schema_json(Dir, PrivDir, SchemaModule) ->
|
gen_schema_json(Dir, I18nFile, SchemaModule) ->
|
||||||
SchemaJsonFile = filename:join([Dir, "schema.json"]),
|
SchemaJsonFile = filename:join([Dir, "schema.json"]),
|
||||||
io:format(user, "===< Generating: ~s~n", [SchemaJsonFile]),
|
io:format(user, "===< Generating: ~s~n", [SchemaJsonFile]),
|
||||||
Opts = #{desc_file => i18n_file(PrivDir), lang => "en"},
|
Opts = #{desc_file => I18nFile, lang => "en"},
|
||||||
JsonMap = hocon_schema_json:gen(SchemaModule, Opts),
|
JsonMap = hocon_schema_json:gen(SchemaModule, Opts),
|
||||||
IoData = jsx:encode(JsonMap, [space, {indent, 4}]),
|
IoData = jsx:encode(JsonMap, [space, {indent, 4}]),
|
||||||
ok = file:write_file(SchemaJsonFile, IoData).
|
ok = file:write_file(SchemaJsonFile, IoData).
|
||||||
|
|
||||||
gen_hot_conf_schema_json(Dir, PrivDir, Lang) ->
|
gen_hot_conf_schema_json(Dir, I18nFile, Lang) ->
|
||||||
emqx_dashboard:init_i18n(i18n_file(PrivDir), Lang),
|
emqx_dashboard:init_i18n(I18nFile, Lang),
|
||||||
JsonFile = "hot-config-schema-" ++ atom_to_list(Lang) ++ ".json",
|
JsonFile = "hot-config-schema-" ++ atom_to_list(Lang) ++ ".json",
|
||||||
HotConfigSchemaFile = filename:join([Dir, JsonFile]),
|
HotConfigSchemaFile = filename:join([Dir, JsonFile]),
|
||||||
io:format(user, "===< Generating: ~s~n", [HotConfigSchemaFile]),
|
io:format(user, "===< Generating: ~s~n", [HotConfigSchemaFile]),
|
||||||
ok = gen_hot_conf_schema(HotConfigSchemaFile),
|
ok = gen_hot_conf_schema(HotConfigSchemaFile),
|
||||||
emqx_dashboard:clear_i18n().
|
emqx_dashboard:clear_i18n().
|
||||||
|
|
||||||
gen_config_md(Dir, PrivDir, SchemaModule, Lang0) ->
|
gen_config_md(Dir, I18nFile, SchemaModule, Lang0) ->
|
||||||
Lang = atom_to_list(Lang0),
|
Lang = atom_to_list(Lang0),
|
||||||
SchemaMdFile = filename:join([Dir, "config-" ++ Lang ++ ".md"]),
|
SchemaMdFile = filename:join([Dir, "config-" ++ Lang ++ ".md"]),
|
||||||
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
|
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
|
||||||
ok = gen_doc(SchemaMdFile, SchemaModule, PrivDir, Lang).
|
ok = gen_doc(SchemaMdFile, SchemaModule, I18nFile, Lang).
|
||||||
|
|
||||||
%% @doc return the root schema module.
|
%% @doc return the root schema module.
|
||||||
-spec schema_module() -> module().
|
-spec schema_module() -> module().
|
||||||
|
@ -182,13 +182,12 @@ schema_module() ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-spec gen_doc(file:name_all(), module(), file:name_all(), string()) -> ok.
|
-spec gen_doc(file:name_all(), module(), file:name_all(), string()) -> ok.
|
||||||
gen_doc(File, SchemaModule, EtcDir, Lang) ->
|
gen_doc(File, SchemaModule, I18nFile, Lang) ->
|
||||||
Version = emqx_release:version(),
|
Version = emqx_release:version(),
|
||||||
Title = "# " ++ emqx_release:description() ++ " " ++ Version ++ " Configuration",
|
Title = "# " ++ emqx_release:description() ++ " " ++ Version ++ " Configuration",
|
||||||
BodyFile = filename:join([code:lib_dir(emqx_conf), "etc", "emqx_conf.md"]),
|
BodyFile = filename:join([code:lib_dir(emqx_conf), "etc", "emqx_conf.md"]),
|
||||||
{ok, Body} = file:read_file(BodyFile),
|
{ok, Body} = file:read_file(BodyFile),
|
||||||
DescFile = i18n_file(EtcDir),
|
Opts = #{title => Title, body => Body, desc_file => I18nFile, lang => Lang},
|
||||||
Opts = #{title => Title, body => Body, desc_file => DescFile, lang => Lang},
|
|
||||||
Doc = hocon_schema_md:gen(SchemaModule, Opts),
|
Doc = hocon_schema_md:gen(SchemaModule, Opts),
|
||||||
file:write_file(File, Doc).
|
file:write_file(File, Doc).
|
||||||
|
|
||||||
|
@ -446,6 +445,3 @@ to_bin(Boolean) when is_boolean(Boolean) -> Boolean;
|
||||||
to_bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8);
|
to_bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8);
|
||||||
to_bin(X) ->
|
to_bin(X) ->
|
||||||
X.
|
X.
|
||||||
|
|
||||||
i18n_file(EtcDir) ->
|
|
||||||
filename:join([EtcDir, "i18n.conf"]).
|
|
||||||
|
|
3
build
3
build
|
@ -82,7 +82,8 @@ make_doc() {
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
erl -noshell -pa $libs_dir1 $libs_dir2 $libs_dir3 -eval \
|
erl -noshell -pa $libs_dir1 $libs_dir2 $libs_dir3 -eval \
|
||||||
"Dir = filename:join(['_build', '${PROFILE}', lib, emqx_dashboard, priv, www, static]), \
|
"Dir = filename:join(['_build', '${PROFILE}', lib, emqx_dashboard, priv, www, static]), \
|
||||||
ok = emqx_conf:dump_schema(Dir, $SCHEMA_MODULE), \
|
I18nFile = filename:join(['_build', '${PROFILE}', lib, emqx_dashboard, etc, 'i18n.conf.all']), \
|
||||||
|
ok = emqx_conf:dump_schema(Dir, $SCHEMA_MODULE, I18nFile), \
|
||||||
halt(0)."
|
halt(0)."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
mix.exs
7
mix.exs
|
@ -341,12 +341,13 @@ defmodule EMQXUmbrella.MixProject do
|
||||||
"apps/emqx/etc/certs",
|
"apps/emqx/etc/certs",
|
||||||
Path.join(etc, "certs")
|
Path.join(etc, "certs")
|
||||||
)
|
)
|
||||||
|
|
||||||
# required by emqx_dashboard
|
# required by emqx_dashboard
|
||||||
Mix.Generator.copy_file(
|
Mix.Generator.copy_file(
|
||||||
"apps/emqx_dashboard/etc/i18n.conf",
|
"apps/emqx_dashboard/etc/i18n.conf.all",
|
||||||
Path.join(etc, "i18n.conf"),
|
Path.join(etc, "i18n.conf"),
|
||||||
force: overwrite?
|
force: overwrite?
|
||||||
)
|
)
|
||||||
|
|
||||||
# this is required by the produced escript / nodetool
|
# this is required by the produced escript / nodetool
|
||||||
Mix.Generator.copy_file(
|
Mix.Generator.copy_file(
|
||||||
|
|
|
@ -62,8 +62,7 @@ get_cfgs(Dir, Cfgs) ->
|
||||||
%% the conf name must start with emqx
|
%% the conf name must start with emqx
|
||||||
%% because there are some other conf, and these conf don't start with emqx
|
%% because there are some other conf, and these conf don't start with emqx
|
||||||
Confs = filelib:wildcard("emqx*.conf", EtcDir),
|
Confs = filelib:wildcard("emqx*.conf", EtcDir),
|
||||||
Confs1 = lists:filter(fun(N) -> string:find(N, "i18n") =:= nomatch end, Confs),
|
NewCfgs = [filename:join([EtcDir, Name]) || Name <- Confs],
|
||||||
NewCfgs = [filename:join([EtcDir, Name]) || Name <- Confs1],
|
|
||||||
try_enter_child(Dir, Files, NewCfgs ++ Cfgs)
|
try_enter_child(Dir, Files, NewCfgs ++ Cfgs)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
-mode(compile).
|
-mode(compile).
|
||||||
|
|
||||||
main(_) ->
|
main(_) ->
|
||||||
{ok, BaseConf} = file:read_file("apps/emqx_dashboard/etc/emqx_dashboard_i18n.conf"),
|
{ok, BaseConf} = file:read_file("apps/emqx_dashboard/i18n/emqx_dashboard_i18n.conf"),
|
||||||
|
|
||||||
Cfgs = get_all_cfgs("apps/"),
|
Cfgs = get_all_cfgs("apps/"),
|
||||||
Conf = [merge(BaseConf, Cfgs),
|
Conf = [merge(BaseConf, Cfgs),
|
||||||
|
@ -40,14 +40,12 @@ get_cfgs(Dir, Cfgs) ->
|
||||||
Cfgs;
|
Cfgs;
|
||||||
_ ->
|
_ ->
|
||||||
Files = filelib:wildcard("*", Dir),
|
Files = filelib:wildcard("*", Dir),
|
||||||
case lists:member("etc", Files) of
|
case lists:member("i18n", Files) of
|
||||||
false ->
|
false ->
|
||||||
try_enter_child(Dir, Files, Cfgs);
|
try_enter_child(Dir, Files, Cfgs);
|
||||||
true ->
|
true ->
|
||||||
EtcDir = filename:join([Dir, "etc"]),
|
EtcDir = filename:join([Dir, "i18n"]),
|
||||||
%% the conf name must start with emqx
|
Confs = filelib:wildcard("*.conf", EtcDir),
|
||||||
%% because there are some other conf, and these conf don't start with emqx
|
|
||||||
Confs = filelib:wildcard("emqx*_i18n.conf", EtcDir),
|
|
||||||
NewCfgs = [filename:join([EtcDir, Name]) || Name <- Confs],
|
NewCfgs = [filename:join([EtcDir, Name]) || Name <- Confs],
|
||||||
try_enter_child(Dir, Files, NewCfgs ++ Cfgs)
|
try_enter_child(Dir, Files, NewCfgs ++ Cfgs)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue