imap-backup 16.4.2 → 16.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  require "highline"
2
+ require "i18n"
2
3
 
3
4
  require "imap/backup/account"
4
5
  require "imap/backup/email/provider"
@@ -41,21 +42,21 @@ module Imap::Backup
41
42
  def show_menu
42
43
  self.class.highline.choose do |menu|
43
44
  menu.header = <<~MENU.chomp
44
- #{helpers.title_prefix} Main Menu
45
+ #{helpers.title_prefix} #{I18n.t('setup.main_menu.title')}
45
46
 
46
- Choose an action
47
+ #{I18n.translate('setup.main_menu.choose_action')}
47
48
  MENU
48
49
  account_items menu
49
50
  add_account_item menu
50
51
  modify_global_options menu
51
52
  if config.modified?
52
- menu.choice("save and exit") do
53
+ menu.choice(I18n.t("setup.main_menu.save_and_exit")) do
53
54
  config.save
54
55
  throw :done
55
56
  end
56
- menu.choice("exit without saving changes") { throw :done }
57
+ menu.choice(I18n.t("setup.main_menu.exit_without_saving")) { throw :done }
57
58
  else
58
- menu.choice("(q) quit") { throw :done }
59
+ menu.choice(I18n.t("setup.main_menu.quit")) { throw :done }
59
60
  menu.hidden("quit") { throw :done }
60
61
  end
61
62
  end
@@ -74,7 +75,7 @@ module Imap::Backup
74
75
  end
75
76
 
76
77
  def add_account_item(menu)
77
- menu.choice("add account") do
78
+ menu.choice(I18n.t("setup.main_menu.add_account")) do
78
79
  username = Asker.email
79
80
  edit_account username
80
81
  end
@@ -82,7 +83,7 @@ module Imap::Backup
82
83
 
83
84
  def modify_global_options(menu)
84
85
  changed = config.download_strategy_modified? ? " *" : ""
85
- menu.choice("modify global options#{changed}") do
86
+ menu.choice("#{I18n.t('setup.main_menu.modify_global_options')}#{changed}") do
86
87
  GlobalOptions.new(config: config).run
87
88
  end
88
89
  end
@@ -0,0 +1,48 @@
1
+ require "i18n"
2
+ require "locale"
3
+
4
+ module Imap; end
5
+
6
+ module Imap::Backup
7
+ # Handles internationalization (i18n) setup and locale detection.
8
+ class Translator
9
+ FALLBACK_LOCALE = :en
10
+
11
+ # Initializes i18n with the detected locale.
12
+ # Sets up load paths and configures fallbacks.
13
+ def setup
14
+ I18n.load_path = locale_files
15
+ I18n.backend.load_translations
16
+ I18n.default_locale = FALLBACK_LOCALE
17
+ I18n.locale = detect_locale
18
+ end
19
+
20
+ private
21
+
22
+ def locale_files
23
+ locales_path = File.expand_path("locales", __dir__)
24
+ Dir.glob(File.join(locales_path, "*.yml"))
25
+ end
26
+
27
+ def detect_locale
28
+ # LANG=C should use English
29
+ return FALLBACK_LOCALE if ENV["LANG"] == "C"
30
+
31
+ tags = Locale.candidates
32
+
33
+ # Find the first locale we have translations for
34
+ tags.each do |tag|
35
+ locale_symbol = tag.language.to_sym
36
+ return locale_symbol if available_locales.include?(locale_symbol)
37
+ end
38
+
39
+ FALLBACK_LOCALE
40
+ end
41
+
42
+ def available_locales
43
+ locale_files.map do |file|
44
+ File.basename(file, ".yml").to_sym
45
+ end
46
+ end
47
+ end
48
+ end
@@ -4,9 +4,9 @@ module Imap::Backup
4
4
  # @private
5
5
  MAJOR = 16
6
6
  # @private
7
- MINOR = 4
7
+ MINOR = 5
8
8
  # @private
9
- REVISION = 2
9
+ REVISION = 0
10
10
  # @private
11
11
  PRE = nil
12
12
  # The application version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.4.2
4
+ version: 16.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
@@ -23,6 +23,34 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: i18n
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: locale
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
26
54
  - !ruby/object:Gem::Dependency
27
55
  name: logger
28
56
  requirement: !ruby/object:Gem::Requirement
@@ -174,9 +202,11 @@ files:
174
202
  - LICENSE
175
203
  - README.md
176
204
  - bin/imap-backup
205
+ - docs/TODO.md
177
206
  - docs/delimiters-and-prefixes.md
178
207
  - docs/development.md
179
208
  - docs/documentation.md
209
+ - docs/i18n.md
180
210
  - docs/performance.md
181
211
  - docs/testing.md
182
212
  - imap-backup.gemspec
@@ -223,6 +253,8 @@ files:
223
253
  - lib/imap/backup/file_mode.rb
224
254
  - lib/imap/backup/flag_refresher.rb
225
255
  - lib/imap/backup/local_only_message_deleter.rb
256
+ - lib/imap/backup/locales/en.yml
257
+ - lib/imap/backup/locales/it.yml
226
258
  - lib/imap/backup/lockfile.rb
227
259
  - lib/imap/backup/logger.rb
228
260
  - lib/imap/backup/migrator.rb
@@ -257,6 +289,7 @@ files:
257
289
  - lib/imap/backup/setup/helpers.rb
258
290
  - lib/imap/backup/text/sanitizer.rb
259
291
  - lib/imap/backup/thunderbird/mailbox_exporter.rb
292
+ - lib/imap/backup/translator.rb
260
293
  - lib/imap/backup/uploader.rb
261
294
  - lib/imap/backup/version.rb
262
295
  homepage: https://github.com/joeyates/imap-backup