refactor: do not generate i18n msgid in dashboard schema json
dashboard has its own mind now i18n is only used to generate docs: 1. runtime swagger spec at /api-docs 2. build-time config schema both result in the resolved i18n text, but not msgid
This commit is contained in:
parent
e7a4210943
commit
afc87ddc9e
|
@ -81,7 +81,7 @@
|
||||||
])
|
])
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(SPECIAL_LANG_MSGID, <<"$msgid">>).
|
-define(NO_I18N, undefined).
|
||||||
|
|
||||||
-define(MAX_ROW_LIMIT, 10000).
|
-define(MAX_ROW_LIMIT, 10000).
|
||||||
-define(DEFAULT_ROW, 100).
|
-define(DEFAULT_ROW, 100).
|
||||||
|
@ -267,7 +267,7 @@ gen_api_schema_json_iodata(SchemaMod, SchemaInfo, Converter) ->
|
||||||
SchemaMod,
|
SchemaMod,
|
||||||
#{
|
#{
|
||||||
schema_converter => Converter,
|
schema_converter => Converter,
|
||||||
i18n_lang => ?SPECIAL_LANG_MSGID
|
i18n_lang => ?NO_I18N
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
ApiSpec = lists:foldl(
|
ApiSpec = lists:foldl(
|
||||||
|
@ -672,10 +672,10 @@ trans_description(Spec, Hocon, Options) ->
|
||||||
?DESC(_, _) = Struct -> get_i18n(<<"desc">>, Struct, undefined, Options);
|
?DESC(_, _) = Struct -> get_i18n(<<"desc">>, Struct, undefined, Options);
|
||||||
Text -> to_bin(Text)
|
Text -> to_bin(Text)
|
||||||
end,
|
end,
|
||||||
case Desc of
|
case Desc =:= undefined of
|
||||||
undefined ->
|
true ->
|
||||||
Spec;
|
Spec;
|
||||||
Desc ->
|
false ->
|
||||||
Desc1 = binary:replace(Desc, [<<"\n">>], <<"<br/>">>, [global]),
|
Desc1 = binary:replace(Desc, [<<"\n">>], <<"<br/>">>, [global]),
|
||||||
Spec#{description => Desc1}
|
Spec#{description => Desc1}
|
||||||
end.
|
end.
|
||||||
|
@ -683,8 +683,8 @@ trans_description(Spec, Hocon, Options) ->
|
||||||
get_i18n(Tag, ?DESC(Namespace, Id), Default, Options) ->
|
get_i18n(Tag, ?DESC(Namespace, Id), Default, Options) ->
|
||||||
Lang = get_lang(Options),
|
Lang = get_lang(Options),
|
||||||
case Lang of
|
case Lang of
|
||||||
?SPECIAL_LANG_MSGID ->
|
?NO_I18N ->
|
||||||
make_msgid(Namespace, Id, Tag);
|
undefined;
|
||||||
_ ->
|
_ ->
|
||||||
get_i18n_text(Lang, Namespace, Id, Tag, Default)
|
get_i18n_text(Lang, Namespace, Id, Tag, Default)
|
||||||
end.
|
end.
|
||||||
|
@ -697,14 +697,6 @@ get_i18n_text(Lang, Namespace, Id, Tag, Default) ->
|
||||||
Text
|
Text
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Format:$msgid:Namespace.Id.Tag
|
|
||||||
%% e.g. $msgid:emqx_schema.key.desc
|
|
||||||
%% $msgid:emqx_schema.key.label
|
|
||||||
%% if needed, the consumer of this schema JSON can use this msgid to
|
|
||||||
%% resolve the text in the i18n database.
|
|
||||||
make_msgid(Namespace, Id, Tag) ->
|
|
||||||
iolist_to_binary(["$msgid:", to_bin(Namespace), ".", to_bin(Id), ".", Tag]).
|
|
||||||
|
|
||||||
%% So far i18n_lang in options is only used at build time.
|
%% So far i18n_lang in options is only used at build time.
|
||||||
%% At runtime, it's still the global config which controls the language.
|
%% At runtime, it's still the global config which controls the language.
|
||||||
get_lang(#{i18n_lang := Lang}) -> Lang;
|
get_lang(#{i18n_lang := Lang}) -> Lang;
|
||||||
|
@ -716,7 +708,12 @@ trans_label(Spec, Hocon, Default, Options) ->
|
||||||
?DESC(_, _) = Struct -> get_i18n(<<"label">>, Struct, Default, Options);
|
?DESC(_, _) = Struct -> get_i18n(<<"label">>, Struct, Default, Options);
|
||||||
_ -> Default
|
_ -> Default
|
||||||
end,
|
end,
|
||||||
Spec#{label => Label}.
|
case Label =:= undefined of
|
||||||
|
true ->
|
||||||
|
Spec;
|
||||||
|
false ->
|
||||||
|
Spec#{label => Label}
|
||||||
|
end.
|
||||||
|
|
||||||
desc_struct(Hocon) ->
|
desc_struct(Hocon) ->
|
||||||
R =
|
R =
|
||||||
|
|
Loading…
Reference in New Issue