lit 0.3.3 → 0.4.0.pre.alpha

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -6
  3. data/app/assets/javascripts/lit/lit_frontend.js +20 -12
  4. data/app/assets/stylesheets/lit/application.css +3 -0
  5. data/app/controllers/lit/api/v1/base_controller.rb +1 -1
  6. data/app/controllers/lit/api/v1/locales_controller.rb +1 -1
  7. data/app/controllers/lit/api/v1/localization_keys_controller.rb +12 -4
  8. data/app/controllers/lit/api/v1/localizations_controller.rb +25 -9
  9. data/app/controllers/lit/application_controller.rb +11 -8
  10. data/app/controllers/lit/concerns/request_info_store.rb +1 -0
  11. data/app/controllers/lit/incomming_localizations_controller.rb +22 -15
  12. data/app/controllers/lit/locales_controller.rb +1 -1
  13. data/app/controllers/lit/localization_keys_controller.rb +44 -18
  14. data/app/controllers/lit/localizations_controller.rb +16 -11
  15. data/app/controllers/lit/sources_controller.rb +9 -13
  16. data/app/helpers/lit/frontend_helper.rb +28 -16
  17. data/app/helpers/lit/localizations_helper.rb +2 -1
  18. data/app/jobs/lit/synchronize_source_job.rb +1 -1
  19. data/app/models/lit/incomming_localization.rb +71 -41
  20. data/app/models/lit/locale.rb +11 -13
  21. data/app/models/lit/localization.rb +26 -24
  22. data/app/models/lit/localization_key.rb +46 -55
  23. data/app/models/lit/source.rb +17 -74
  24. data/app/queries/localization_key_search_query.rb +80 -0
  25. data/app/services/remote_interactor_service.rb +45 -0
  26. data/app/services/synchronize_source_service.rb +63 -0
  27. data/app/views/kaminari/lit/_gap.html.erb +1 -1
  28. data/app/views/layouts/lit/_navigation.html.erb +1 -1
  29. data/app/views/lit/dashboard/index.html.erb +2 -2
  30. data/app/views/lit/incomming_localizations/index.html.erb +10 -6
  31. data/app/views/lit/localization_keys/_localization_row.html.erb +1 -1
  32. data/app/views/lit/localization_keys/_localizations_list.html.erb +84 -0
  33. data/app/views/lit/localization_keys/_sidebar.html.erb +66 -0
  34. data/app/views/lit/localization_keys/change_completed.js.erb +2 -0
  35. data/app/views/lit/localization_keys/index.html.erb +3 -121
  36. data/app/views/lit/localization_keys/not_translated.html.erb +9 -0
  37. data/app/views/lit/localization_keys/restore_deleted.js.erb +1 -0
  38. data/app/views/lit/localization_keys/visited_again.html.erb +9 -0
  39. data/app/views/lit/localizations/_previous_versions_rows.html.erb +2 -2
  40. data/app/views/lit/localizations/change_completed.js.erb +2 -0
  41. data/app/views/lit/localizations/update.js.erb +2 -0
  42. data/app/views/lit/sources/_form.html.erb +1 -1
  43. data/app/views/lit/sources/index.html.erb +1 -1
  44. data/config/routes.rb +5 -0
  45. data/db/migrate/20181017123839_lit_add_is_deleted_to_localization_keys.rb +8 -0
  46. data/db/migrate/20181018075955_lit_add_localization_key_is_deleted_to_localization_keys.rb +8 -0
  47. data/db/migrate/20181030111522_lit_add_is_visited_again_to_localization_keys.rb +8 -0
  48. data/lib/generators/lit/install/templates/initializer.rb +5 -1
  49. data/lib/lit.rb +1 -0
  50. data/lib/lit/adapters/redis_storage.rb +1 -1
  51. data/lib/lit/cache.rb +32 -54
  52. data/lib/lit/export.rb +80 -0
  53. data/lib/lit/i18n_backend.rb +12 -9
  54. data/lib/lit/import.rb +179 -0
  55. data/lib/lit/loader.rb +2 -0
  56. data/lib/lit/version.rb +1 -1
  57. data/lib/tasks/lit_tasks.rake +78 -13
  58. metadata +21 -6
data/lib/lit/loader.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'logger'
2
2
  require 'lit/i18n_backend'
3
3
  require 'lit/cache'
4
+ require 'lit/export'
5
+ require 'lit/import'
4
6
 
5
7
  module Lit
6
8
  class Loader
data/lib/lit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lit
2
- VERSION = '0.3.3'.freeze
2
+ VERSION = '0.4.0-alpha'.freeze
3
3
  end
@@ -1,29 +1,94 @@
1
1
  namespace :lit do
2
2
  desc 'Exports translated strings from lit to config/locales/lit.yml file.'
3
3
  task export: :environment do
4
- if yml = Lit.init.cache.export
5
- path = Rails.root.join('config', 'locales', 'lit.yml')
6
- File.new(path, 'w').write(yml)
4
+ locale_keys = ENV['LOCALES'].to_s.split(',') || []
5
+ export_format = ENV['FORMAT'].presence&.downcase&.to_sym || :yaml
6
+ path = ENV['OUTPUT'].presence || Rails.root.join('config', 'locales', "lit.#{file_extension(export_format)}")
7
+
8
+ if exported = Lit::Export.call(locale_keys: locale_keys, format: export_format)
9
+ File.new(path, 'w').write(exported)
7
10
  puts "Successfully exported #{path}."
8
11
  end
9
12
  end
10
13
 
11
- desc 'Reads config/locales/#{ENV["FILES"]} files and calls I18n.t() on keys forcing Lit to import given LOCALE to cache / to display them in UI. Skips nils by default (change by setting ENV["SKIP_NIL"] = false'
12
- task raw_import: :environment do
13
- return 'you need to define FILES env' if ENV['FILES'].blank?
14
- return 'you need to define LOCALE env' if ENV['LOCALE'].blank?
14
+ desc 'Exports translated strings from lit to config/locales/%{locale}.yml file.'
15
+ task export_splitted: :environment do
16
+ locale_keys = ENV['LOCALES'].to_s.split(',').presence || I18n.available_locales
17
+ export_format = ENV['FORMAT'].presence&.downcase&.to_sym || :yaml
18
+
19
+ locale_keys.each do |loc|
20
+ path = Rails.root.join('config', 'locales',
21
+ "#{loc}.#{file_extension(export_format)}")
22
+ if exported = Lit::Export.call(locale_keys: locale_keys, format: export_format)
23
+ File.write(path, exported)
24
+ puts "Successfully exported #{path}."
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "Imports locales given in ENV['LOCALES'] (optional, imports all " \
30
+ "locales by default, from file given in ENV['FILE']; FILE may be " \
31
+ "a YAML or CSV (comma- or tab-separated) file."
32
+ task import: :environment do
33
+ locale_keys = ENV.fetch('LOCALES', '').split(',')
34
+ raise 'you need to define FILE env' unless filename = ENV.fetch('FILE', nil)
35
+ format =
36
+ case filename
37
+ when /\.csv\z/, /\.tsv\z/ then :csv
38
+ when /\.yml\z/, /\.yaml\z/ then :yaml
39
+ else raise 'file must be a CSV or YAML file'
40
+ end
41
+ input = File.open(filename)
42
+ skip_nil = ['1', 'true'].include?(ENV['SKIP_NIL']) # defaults to false
43
+ Lit::Import.call(
44
+ input: input,
45
+ locale_keys: locale_keys,
46
+ format: format,
47
+ skip_nil: skip_nil,
48
+ raw: false
49
+ )
50
+ end
51
+
52
+ warm_up_keys_desc =
53
+ 'Reads config/locales/#{ENV["FILES"]} files and calls I18n.t() on ' \
54
+ 'keys forcing Lit to import given LOCALE to cache / to display them' \
55
+ ' in UI. Skips nils by default (change by setting ENV["SKIP_NIL"] = false'
56
+ desc warm_up_keys_desc
57
+ task warm_up_keys: :environment do
58
+ raise 'you need to define FILES env' if ENV['FILES'].blank?
59
+ raise 'you need to define LOCALE env' if ENV['LOCALE'].blank?
15
60
  files = ENV['FILES'].to_s.split(',')
16
61
  locale = ENV['LOCALE'].to_s
62
+ skip_nil = ['1', 'true'].include?(ENV['SKIP_NIL'])
17
63
  I18n.with_locale(locale) do
18
64
  files.each do |file|
19
65
  locale_file = File.open(Rails.root.join('config', 'locales', file))
20
- yml = YAML.load(locale_file)[locale]
21
- Hash[*Lit::Cache.flatten_hash(yml)].each do |key, default_translation|
22
- next if default_translation.nil? && ENV.fetch('SKIP_NIL', 'true') == 'true'
23
- puts key
24
- I18n.t(key, default: default_translation)
25
- end
66
+ Lit::Import.call(
67
+ input: locale_file,
68
+ locale_keys: [locale],
69
+ format: :yaml,
70
+ skip_nil: skip_nil,
71
+ raw: true
72
+ )
26
73
  end
27
74
  end
28
75
  end
76
+
77
+ desc "[DEPRECATED - use lit:warm_up_keys instead] #{warm_up_keys_desc}"
78
+ task raw_import: :warm_up_keys
79
+
80
+ desc 'Remove all translations'
81
+ task clear: :environment do
82
+ Lit::LocalizationKey.destroy_all
83
+ Lit::IncommingLocalization.destroy_all
84
+ Lit.init.cache.reset
85
+ end
86
+
87
+ def file_extension(format)
88
+ case format.to_sym
89
+ when :yaml then 'yml'
90
+ when :csv then 'csv'
91
+ else raise ArgumentError
92
+ end
93
+ end
29
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Litwiniuk
@@ -10,20 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-05 00:00:00.000000000 Z
13
+ date: 2018-11-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0.7'
29
29
  - !ruby/object:Gem::Dependency
@@ -396,6 +396,9 @@ files:
396
396
  - app/models/lit/localization_key.rb
397
397
  - app/models/lit/localization_version.rb
398
398
  - app/models/lit/source.rb
399
+ - app/queries/localization_key_search_query.rb
400
+ - app/services/remote_interactor_service.rb
401
+ - app/services/synchronize_source_service.rb
399
402
  - app/views/kaminari/lit/_first_page.html.erb
400
403
  - app/views/kaminari/lit/_gap.html.erb
401
404
  - app/views/kaminari/lit/_last_page.html.erb
@@ -414,11 +417,18 @@ files:
414
417
  - app/views/lit/locales/hide.js.erb
415
418
  - app/views/lit/locales/index.html.erb
416
419
  - app/views/lit/localization_keys/_localization_row.html.erb
420
+ - app/views/lit/localization_keys/_localizations_list.html.erb
421
+ - app/views/lit/localization_keys/_sidebar.html.erb
422
+ - app/views/lit/localization_keys/change_completed.js.erb
417
423
  - app/views/lit/localization_keys/destroy.js.erb
418
424
  - app/views/lit/localization_keys/index.html.erb
425
+ - app/views/lit/localization_keys/not_translated.html.erb
426
+ - app/views/lit/localization_keys/restore_deleted.js.erb
419
427
  - app/views/lit/localization_keys/star.js.erb
428
+ - app/views/lit/localization_keys/visited_again.html.erb
420
429
  - app/views/lit/localizations/_form.html.erb
421
430
  - app/views/lit/localizations/_previous_versions_rows.html.erb
431
+ - app/views/lit/localizations/change_completed.js.erb
422
432
  - app/views/lit/localizations/edit.js.erb
423
433
  - app/views/lit/localizations/previous_versions.js.erb
424
434
  - app/views/lit/localizations/update.js.erb
@@ -437,6 +447,9 @@ files:
437
447
  - db/migrate/20180101010107_lit_create_lit_sources.rb
438
448
  - db/migrate/20180101010108_lit_create_lit_incomming_localizations.rb
439
449
  - db/migrate/20180101010109_lit_add_sync_complete_to_lit_sources.rb
450
+ - db/migrate/20181017123839_lit_add_is_deleted_to_localization_keys.rb
451
+ - db/migrate/20181018075955_lit_add_localization_key_is_deleted_to_localization_keys.rb
452
+ - db/migrate/20181030111522_lit_add_is_visited_again_to_localization_keys.rb
440
453
  - lib/generators/lit/install/templates/initializer.rb
441
454
  - lib/generators/lit/install_generator.rb
442
455
  - lib/lit.rb
@@ -444,7 +457,9 @@ files:
444
457
  - lib/lit/adapters/redis_storage.rb
445
458
  - lib/lit/cache.rb
446
459
  - lib/lit/engine.rb
460
+ - lib/lit/export.rb
447
461
  - lib/lit/i18n_backend.rb
462
+ - lib/lit/import.rb
448
463
  - lib/lit/loader.rb
449
464
  - lib/lit/rails.rb
450
465
  - lib/lit/railtie.rb
@@ -465,9 +480,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
465
480
  version: '0'
466
481
  required_rubygems_version: !ruby/object:Gem::Requirement
467
482
  requirements:
468
- - - ">="
483
+ - - ">"
469
484
  - !ruby/object:Gem::Version
470
- version: '0'
485
+ version: 1.3.1
471
486
  requirements: []
472
487
  rubyforge_project:
473
488
  rubygems_version: 2.6.13