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"
|
||||
path: |
|
||||
scripts/spellcheck
|
||||
_build/docgen/${{ matrix.profile[0] }}/schema.json
|
||||
_build/docgen/${{ matrix.profile[0] }}/schema-en.json
|
||||
|
||||
windows:
|
||||
runs-on: windows-2019
|
||||
|
@ -218,4 +218,4 @@ jobs:
|
|||
path: /tmp/
|
||||
- name: Run spellcheck
|
||||
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) ->
|
||||
gen_config_md(Dir, I18nFile, SchemaModule, 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,
|
||||
[en, zh]
|
||||
),
|
||||
gen_schema_json(Dir, I18nFile, SchemaModule).
|
||||
["en", "zh"]
|
||||
).
|
||||
|
||||
%% for scripts/spellcheck.
|
||||
gen_schema_json(Dir, I18nFile, SchemaModule) ->
|
||||
SchemaJsonFile = filename:join([Dir, "schema.json"]),
|
||||
gen_schema_json(Dir, I18nFile, SchemaModule, Lang) ->
|
||||
SchemaJsonFile = filename:join([Dir, "schema-" ++ Lang ++ ".json"]),
|
||||
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),
|
||||
IoData = jsx:encode(JsonMap, [space, {indent, 4}]),
|
||||
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).
|
||||
|
||||
schema_filename(Dir, Prefix, Lang) ->
|
||||
Filename = Prefix ++ atom_to_list(Lang) ++ ".json",
|
||||
Filename = Prefix ++ Lang ++ ".json",
|
||||
filename:join([Dir, Filename]).
|
||||
|
||||
gen_config_md(Dir, I18nFile, SchemaModule, Lang0) ->
|
||||
Lang = atom_to_list(Lang0),
|
||||
gen_config_md(Dir, I18nFile, SchemaModule, Lang) ->
|
||||
SchemaMdFile = filename:join([Dir, "config-" ++ Lang ++ ".md"]),
|
||||
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
|
||||
ok = gen_doc(SchemaMdFile, SchemaModule, I18nFile, Lang).
|
||||
|
||||
gen_example_conf(Dir, I18nFile, SchemaModule, Lang0) ->
|
||||
Lang = atom_to_list(Lang0),
|
||||
gen_example_conf(Dir, I18nFile, SchemaModule, Lang) ->
|
||||
SchemaMdFile = filename:join([Dir, "emqx.conf." ++ Lang ++ ".example"]),
|
||||
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
|
||||
ok = gen_example(SchemaMdFile, SchemaModule, I18nFile, Lang).
|
||||
|
|
|
@ -132,9 +132,11 @@ stop_listeners(Listeners) ->
|
|||
get_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),
|
||||
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() ->
|
||||
case application:get_env(emqx_dashboard, i18n) of
|
||||
|
|
Loading…
Reference in New Issue