Adds a first-run wallet and account creator option for noobs. If they select the "create a default wallet" option, they are jumped to the name + password screen for wallet creation, and a new account is generated for them named "Account 1". This leapfrogs the problem of users having to know what is going on with the blockchain and wallet at all before getting started. #18 #19 Reviewed-on: #24 Reviewed-by: Ulf Wiger <ulfwiger@qpq.swiss> Co-authored-by: Craig Everett <zxq9@zxq9.com> Co-committed-by: Craig Everett <zxq9@zxq9.com>
41 lines
1.7 KiB
Erlang
41 lines
1.7 KiB
Erlang
%%% A rework of the JumpText idea. To be adapted into actual JumpText for v2.0.
|
|
%%% To add translations to a module you add a file named ?MODULE.trans to priv/i18n/.
|
|
%%% The file contains an Erlang terms file of the form:
|
|
%%% `{LangCode :: atom(), Translations :: #{Phrase :: string() := Translation :: string()}}'
|
|
%%% The entire file's contents are returned by `read_translations/1'.
|
|
%%% The function `j/2' extracts the dictionary requested and returns a translation
|
|
%%% function that closes over the desired phrase dictionary.
|
|
%%% The customary way to insert translations into a program is to assign the translation
|
|
%%% closure the name `J' and keep it in the local process state. When the user selects
|
|
%%% another language, create a new `J' with the desired language.
|
|
%%%
|
|
%%% `oneshot_j/2' is a convenience function for those who don't intend to keep the
|
|
%%% library of translations in memory (calling `oneshot_j/2' will always perform a disk
|
|
%%% read, where `j/2' could be called any number of times without a disk read if the
|
|
%%% translation library is retained).
|
|
|
|
-module(gd_jt).
|
|
-vsn("0.7.0").
|
|
-export([read_translations/1, j/2, oneshot_j/2]).
|
|
|
|
|
|
read_translations(Module) ->
|
|
File = atom_to_list(Module) ++ ".trans",
|
|
Path = filename:join([zx:get_home(), "priv", "i18n", File]),
|
|
case file:consult(Path) of
|
|
{ok, Translations} -> Translations;
|
|
{error, enoent} -> []
|
|
end.
|
|
|
|
|
|
j(Lang, Translations) ->
|
|
case proplists:get_value(Lang, Translations, none) of
|
|
none -> fun(Phrase) -> Phrase end;
|
|
Dict -> fun(Phrase) -> maps:get(Phrase, Dict, Phrase) end
|
|
end.
|
|
|
|
|
|
oneshot_j(Module, Lang) ->
|
|
Translations = read_translations(Module),
|
|
j(Lang, Translations).
|