fractual_i18n 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 129ab31c55042e1c874a3bfc3bf2fd5138b05ca12096422a3560df6996a92c5a
4
- data.tar.gz: 65fbb964162111aeb79513a2d6400ea89bac32c58d47e00f101f64d54df5d117
3
+ metadata.gz: dbc63f46c1fdd06288309c9f97fba5b93113c88b34a764b3f3672ed4696388b2
4
+ data.tar.gz: 5505013bd5be201fce05544a503babee28d684e3f172821dc6712894331b7aae
5
5
  SHA512:
6
- metadata.gz: 6838fecf53905311dc16fdc8172499cf3d12dc684114956815723c0f9e452e7837b77c43c60dc8a6ea1ebf2f5dbec245654eaddcc5b195054d11a7307b26f9c1
7
- data.tar.gz: 922b001301f42058c7f7b0c52518426a0d7daff6e1c5fa799105a9a32c744e86e336324d8b49105dc60dc1a81cd9e7e20336258ab415d864fac8435f4176b7f4
6
+ metadata.gz: 4f8f898c1184787dd7ccbe6c486d3b5e3060751f457d33db3fc2a6f8a97634b066adca816a08e5745e6263285dacdd305a18d0b530ba1b39852a50c1888bf2c5
7
+ data.tar.gz: 3c7cadc27314a49efbc89497bb5bf37689e8bc15cfd3c2de0974aac131b7e2dab7b34bce0198479d2e76d7cda9afa4adda689635208128aef2ee97e93430cc91
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fractual_i18n (0.1.0)
4
+ fractual_i18n (0.2.0)
5
5
  i18n
6
6
 
7
7
  GEM
@@ -0,0 +1,34 @@
1
+ class FractualI18n::Phrases
2
+ def joined(locale:)
3
+ original_load_path = I18n.load_path
4
+
5
+ I18n.load_path = fractual_files
6
+ I18n.with_locale(locale) { I18n.t(".") }
7
+ ensure
8
+ I18n.load_path = original_load_path
9
+ end
10
+
11
+ def store(translations, locale:)
12
+ fractual_files.each do |filename|
13
+ content = YAML.load_file(filename)
14
+
15
+ fractual_path = FractualI18n.configuration.fractual_paths.find { |path| filename.starts_with?(path) }
16
+ keys = filename.delete_prefix(fractual_path).delete_prefix("/").split("/")
17
+ last_key = keys.pop.delete_suffix(".yml")
18
+ keys << last_key
19
+ keys.map! { |key| key.delete_prefix("_") } # remove underscore from partial name
20
+
21
+ content[locale.to_s] = content.fetch(locale.to_s, {}).merge(translations.dig(locale.to_s, *keys))
22
+
23
+ File.write(filename, content.to_yaml(line_width: 200))
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def fractual_files
30
+ I18n.load_path.select do |path|
31
+ FractualI18n.configuration.fractual_paths.any? { |fp| path.starts_with?(fp) }
32
+ end
33
+ end
34
+ end
@@ -4,4 +4,8 @@ class FractualI18n::Railtie < Rails::Railtie
4
4
  initializer "fractual_i18n.set_fractual_paths" do |app|
5
5
  FractualI18n.configuration.fractual_paths = app.config.paths["app/views"].existent
6
6
  end
7
+
8
+ rake_tasks do
9
+ load "tasks/fractual_i18n.rake"
10
+ end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module FractualI18n
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,30 @@
1
+ namespace :fractual_i18n do
2
+ desc "Export view translations to single file"
3
+ task :export, [:to] => :environment do |_task, args|
4
+ require "fractual_i18n/phrases"
5
+ destination = args[:to] || "tmp/fractual_i18n/exported"
6
+
7
+ FileUtils.mkdir_p(destination)
8
+ FractualI18n.configuration.available_locales.each do |locale|
9
+ translations = FractualI18n::Phrases.new.joined(locale: locale)
10
+ Dir.chdir(destination) do
11
+ content = {locale.to_s => translations.deep_stringify_keys}.to_yaml(line_width: 200)
12
+ File.write("#{locale}.yml", content)
13
+ puts "#{destination}/#{locale}.yml exported"
14
+ end
15
+ end
16
+ end
17
+
18
+ desc "Import view translations from single file"
19
+ task :import, [:from] => :environment do |_task, args|
20
+ require "fractual_i18n/phrases"
21
+ destination = args[:from] || "tmp/fractual_i18n/import"
22
+
23
+ Dir.each_child(destination) do |file|
24
+ content = YAML.load_file("#{destination}/#{file}")
25
+ locale = content.keys.first
26
+
27
+ FractualI18n::Phrases.new.store(content, locale: locale)
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fractual_i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Sęk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-08-26 00:00:00.000000000 Z
12
+ date: 2020-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -44,8 +44,10 @@ files:
44
44
  - lib/fractual_i18n.rb
45
45
  - lib/fractual_i18n/backend.rb
46
46
  - lib/fractual_i18n/configuration.rb
47
+ - lib/fractual_i18n/phrases.rb
47
48
  - lib/fractual_i18n/railtie.rb
48
49
  - lib/fractual_i18n/version.rb
50
+ - lib/tasks/fractual_i18n.rake
49
51
  homepage: https://github.com/tiramizoo/fractual_i18n
50
52
  licenses:
51
53
  - MIT
@@ -67,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  - !ruby/object:Gem::Version
68
70
  version: '0'
69
71
  requirements: []
70
- rubygems_version: 3.1.2
72
+ rubygems_version: 3.1.4
71
73
  signing_key:
72
74
  specification_version: 4
73
75
  summary: Supports loading translation files from views folder