fractual_i18n 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fractual_i18n/phrases.rb +34 -0
- data/lib/fractual_i18n/railtie.rb +4 -0
- data/lib/fractual_i18n/version.rb +1 -1
- data/lib/tasks/fractual_i18n.rake +30 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc63f46c1fdd06288309c9f97fba5b93113c88b34a764b3f3672ed4696388b2
|
4
|
+
data.tar.gz: 5505013bd5be201fce05544a503babee28d684e3f172821dc6712894331b7aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f8f898c1184787dd7ccbe6c486d3b5e3060751f457d33db3fc2a6f8a97634b066adca816a08e5745e6263285dacdd305a18d0b530ba1b39852a50c1888bf2c5
|
7
|
+
data.tar.gz: 3c7cadc27314a49efbc89497bb5bf37689e8bc15cfd3c2de0974aac131b7e2dab7b34bce0198479d2e76d7cda9afa4adda689635208128aef2ee97e93430cc91
|
data/Gemfile.lock
CHANGED
@@ -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
|
@@ -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.
|
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-
|
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.
|
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
|