From 24f7927ac00e5d17e79f1cbb134bc2331ab83969 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sat, 18 Nov 2023 19:58:48 +0100 Subject: [PATCH] feat: add basic support for i18n --- data/locales/en.yaml | 5 +++++ data/locales/fr.yaml | 5 +++++ shard.lock | 14 +++++++++++++- shard.yml | 7 +++++++ src/cli.cr | 7 ++++++- src/file_storage.cr | 7 +++++++ src/main.cr | 1 + 7 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 data/locales/en.yaml create mode 100644 data/locales/fr.yaml create mode 100644 src/file_storage.cr diff --git a/data/locales/en.yaml b/data/locales/en.yaml new file mode 100644 index 0000000..3f8bba2 --- /dev/null +++ b/data/locales/en.yaml @@ -0,0 +1,5 @@ +--- +en: + cli: + banner: "Usage: %{program_name} [options]\n\nGlobal options" +# diff --git a/data/locales/fr.yaml b/data/locales/fr.yaml new file mode 100644 index 0000000..bf79aec --- /dev/null +++ b/data/locales/fr.yaml @@ -0,0 +1,5 @@ +--- +fr: + cli: + banner: "Usage: %{program_name} [options]\n\nOptions globales" +# diff --git a/shard.lock b/shard.lock index 308912c..f765285 100644 --- a/shard.lock +++ b/shard.lock @@ -1,6 +1,18 @@ +--- version: 2.0 shards: + baked_file_system: + git: https://github.com/schovi/baked_file_system.git + version: 0.10.0 + + crinja: + git: https://github.com/straight-shoota/crinja.git + version: 0.8.1 + + i18n: + git: https://github.com/crystal-i18n/i18n.git + version: 0.2.1 + shellwords: git: https://github.com/sztheory/shellwords-crystal.git version: 0.1.0 - diff --git a/shard.yml b/shard.yml index 314293a..4dc5702 100644 --- a/shard.yml +++ b/shard.yml @@ -20,6 +20,13 @@ targets: dependencies: shellwords: github: szTheory/shellwords-crystal + version: 0.1.0 + baked_file_system: + github: schovi/baked_file_system + version: 0.10.0 + i18n: + github: crystal-i18n/i18n + version: 0.2.1 # dependencies: # pg: diff --git a/src/cli.cr b/src/cli.cr index a222201..7ec1a62 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -3,6 +3,7 @@ # SPDX-FileCopyrightText: 2023 Glenn Y. Rolland # Copyright © 2023 Glenn Y. Rolland +require "i18n" require "option_parser" require "./config" require "./fzf" @@ -16,6 +17,10 @@ module GX def initialize() # Main execution starts here + I18n.config.loaders << I18n::Loader::YAML.embed("data/locales") + I18n.config.default_locale = :en + I18n.activate(:fr) ## FIXME: load from environment + I18n.init @config = Config.new ## FIXME: check that FZF is installed @@ -26,7 +31,7 @@ module GX add_args = { name: "", path: "" } delete_args = { name: "" } pparser = OptionParser.new do |parser| - parser.banner = "Usage: #{PROGRAM_NAME} [options]\n\nGlobal options" + parser.banner = I18n.t("cli.banner", program_name: PROGRAM_NAME) parser.on("-c", "--config FILE", "Set configuration file") do |path| @config.path = path diff --git a/src/file_storage.cr b/src/file_storage.cr new file mode 100644 index 0000000..ee31fde --- /dev/null +++ b/src/file_storage.cr @@ -0,0 +1,7 @@ +require "baked_file_system" + +class FileStorage + extend BakedFileSystem + + bake_folder "../data" +end diff --git a/src/main.cr b/src/main.cr index 43192b0..5b0e2c2 100644 --- a/src/main.cr +++ b/src/main.cr @@ -8,6 +8,7 @@ require "colorize" require "json" require "./filesystems/gocryptfs" +require "./file_storage" require "./config" require "./cli"