build: generate per-lang schema dump
This commit is contained in:
parent
91a57faa95
commit
ad1deedd0e
|
@ -82,7 +82,7 @@ jobs:
|
||||||
name: "${{ matrix.profile[0] }}_schema_dump"
|
name: "${{ matrix.profile[0] }}_schema_dump"
|
||||||
path: |
|
path: |
|
||||||
scripts/spellcheck
|
scripts/spellcheck
|
||||||
_build/docgen/${{ matrix.profile[0] }}/schema.json
|
_build/docgen/${{ matrix.profile[0] }}/schema-en.json
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
|
@ -218,4 +218,4 @@ jobs:
|
||||||
path: /tmp/
|
path: /tmp/
|
||||||
- name: Run spellcheck
|
- name: Run spellcheck
|
||||||
run: |
|
run: |
|
||||||
bash /tmp/scripts/spellcheck/spellcheck.sh /tmp/_build/docgen/${{ matrix.profile }}/schema.json
|
bash /tmp/scripts/spellcheck/spellcheck.sh /tmp/_build/docgen/${{ matrix.profile }}/schema-en.json
|
||||||
|
|
|
@ -146,17 +146,17 @@ dump_schema(Dir, SchemaModule, I18nFile) ->
|
||||||
fun(Lang) ->
|
fun(Lang) ->
|
||||||
gen_config_md(Dir, I18nFile, SchemaModule, Lang),
|
gen_config_md(Dir, I18nFile, SchemaModule, Lang),
|
||||||
gen_api_schema_json(Dir, I18nFile, Lang),
|
gen_api_schema_json(Dir, I18nFile, Lang),
|
||||||
gen_example_conf(Dir, I18nFile, SchemaModule, Lang)
|
gen_example_conf(Dir, I18nFile, SchemaModule, Lang),
|
||||||
|
gen_schema_json(Dir, I18nFile, SchemaModule, Lang)
|
||||||
end,
|
end,
|
||||||
[en, zh]
|
["en", "zh"]
|
||||||
),
|
).
|
||||||
gen_schema_json(Dir, I18nFile, SchemaModule).
|
|
||||||
|
|
||||||
%% for scripts/spellcheck.
|
%% for scripts/spellcheck.
|
||||||
gen_schema_json(Dir, I18nFile, SchemaModule) ->
|
gen_schema_json(Dir, I18nFile, SchemaModule, Lang) ->
|
||||||
SchemaJsonFile = filename:join([Dir, "schema.json"]),
|
SchemaJsonFile = filename:join([Dir, "schema-" ++ Lang ++ ".json"]),
|
||||||
io:format(user, "===< Generating: ~s~n", [SchemaJsonFile]),
|
io:format(user, "===< Generating: ~s~n", [SchemaJsonFile]),
|
||||||
Opts = #{desc_file => I18nFile, lang => "en"},
|
Opts = #{desc_file => I18nFile, lang => Lang},
|
||||||
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).
|
||||||
|
@ -178,17 +178,15 @@ gen_api_schema_json_bridge(Dir, Lang) ->
|
||||||
ok = do_gen_api_schema_json(File, emqx_bridge_api, SchemaInfo).
|
ok = do_gen_api_schema_json(File, emqx_bridge_api, SchemaInfo).
|
||||||
|
|
||||||
schema_filename(Dir, Prefix, Lang) ->
|
schema_filename(Dir, Prefix, Lang) ->
|
||||||
Filename = Prefix ++ atom_to_list(Lang) ++ ".json",
|
Filename = Prefix ++ Lang ++ ".json",
|
||||||
filename:join([Dir, Filename]).
|
filename:join([Dir, Filename]).
|
||||||
|
|
||||||
gen_config_md(Dir, I18nFile, SchemaModule, Lang0) ->
|
gen_config_md(Dir, I18nFile, SchemaModule, Lang) ->
|
||||||
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, I18nFile, Lang).
|
ok = gen_doc(SchemaMdFile, SchemaModule, I18nFile, Lang).
|
||||||
|
|
||||||
gen_example_conf(Dir, I18nFile, SchemaModule, Lang0) ->
|
gen_example_conf(Dir, I18nFile, SchemaModule, Lang) ->
|
||||||
Lang = atom_to_list(Lang0),
|
|
||||||
SchemaMdFile = filename:join([Dir, "emqx.conf." ++ Lang ++ ".example"]),
|
SchemaMdFile = filename:join([Dir, "emqx.conf." ++ Lang ++ ".example"]),
|
||||||
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
|
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
|
||||||
ok = gen_example(SchemaMdFile, SchemaModule, I18nFile, Lang).
|
ok = gen_example(SchemaMdFile, SchemaModule, I18nFile, Lang).
|
||||||
|
|
|
@ -132,9 +132,11 @@ stop_listeners(Listeners) ->
|
||||||
get_i18n() ->
|
get_i18n() ->
|
||||||
application:get_env(emqx_dashboard, i18n).
|
application:get_env(emqx_dashboard, i18n).
|
||||||
|
|
||||||
init_i18n(File, Lang) ->
|
init_i18n(File, Lang) when is_atom(Lang) ->
|
||||||
|
init_i18n(File, atom_to_list(Lang));
|
||||||
|
init_i18n(File, Lang) when is_list(Lang) ->
|
||||||
Cache = hocon_schema:new_desc_cache(File),
|
Cache = hocon_schema:new_desc_cache(File),
|
||||||
application:set_env(emqx_dashboard, i18n, #{lang => atom_to_binary(Lang), cache => Cache}).
|
application:set_env(emqx_dashboard, i18n, #{lang => Lang, cache => Cache}).
|
||||||
|
|
||||||
clear_i18n() ->
|
clear_i18n() ->
|
||||||
case application:get_env(emqx_dashboard, i18n) of
|
case application:get_env(emqx_dashboard, i18n) of
|
||||||
|
|
Loading…
Reference in New Issue