rosette 0.2.0 → 0.3.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/app/views/rosette/new.html.erb +1 -1
- data/bin/rails +19 -0
- data/bin/rosette +22 -0
- data/lib/rosette/cli.rb +71 -0
- data/lib/rosette/manager.rb +8 -4
- data/lib/rosette/version.rb +1 -1
- data/lib/rosette.rb +5 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97ee90651ff8eb4ca983a10bf740934c878df05922013c149306b42e56778f21
|
4
|
+
data.tar.gz: 78b300250348617901cd7d2165b9fe0763ad49bf3327850ffdb2852d9dd55678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 182c58aa6fa14ba3b25aaf89d11dcc8e1c461fda6d1fd92b34ab709f98eade14da02d6afd66b994c4ddb2191f07ae5c5db281b131c2dfa280ff6c94bdb616761
|
7
|
+
data.tar.gz: d6a1b2bb51890b68a9f33d9bd3aa799a55a7cc6135abdd614747ca2118bf6a139c50ae0874f5d99dcd5fa160d700c5a344bc5eb333bb4fe229549c4724bf74ee
|
@@ -12,7 +12,7 @@
|
|
12
12
|
<%= f.hidden_field :redirect_path, value: redirect_path %>
|
13
13
|
|
14
14
|
<%= f.fields_for :available_locales do |a| %>
|
15
|
-
<%
|
15
|
+
<% Rosette.available_locales.each do |locale| %>
|
16
16
|
<%= a.label locale, "#{locale.capitalize} translation:" %>
|
17
17
|
<%= a.text_field locale, required: false, label: false, class: 'input-text' %>
|
18
18
|
<% end %>
|
data/bin/rails
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path("..", __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path("../lib/rosette/engine", __dir__)
|
7
|
+
APP_PATH = File.expand_path("../spec/example_app/config/application", __dir__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
11
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
12
|
+
|
13
|
+
require "rails"
|
14
|
+
|
15
|
+
require "action_controller/railtie"
|
16
|
+
require "action_view/railtie"
|
17
|
+
require "active_model/railtie"
|
18
|
+
require "active_record/railtie"
|
19
|
+
require "rails/engine/commands"
|
data/bin/rosette
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
begin
|
5
|
+
require File.join(Dir.pwd, 'config/environment')
|
6
|
+
rescue LoadError
|
7
|
+
puts <<~ERR
|
8
|
+
Could not load your Rails app
|
9
|
+
=============================
|
10
|
+
Rosette assumes you have a config/environment.rb file it can load. If this is the case, please
|
11
|
+
make sure you are using Rosette CLI from the root of your Rails application. Do not hesitate to
|
12
|
+
raise an issue if you need further assistance.
|
13
|
+
ERR
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rosette'
|
18
|
+
|
19
|
+
command = ARGV.shift
|
20
|
+
ARGV.clear
|
21
|
+
|
22
|
+
Rosette::CLI.run(command: command)
|
data/lib/rosette/cli.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
class CLI
|
5
|
+
COMMANDS = %w[add remove read].freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def run(command:)
|
9
|
+
return display_help unless command.in?(COMMANDS)
|
10
|
+
|
11
|
+
ask_user_for_key
|
12
|
+
send(command)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def read
|
18
|
+
Rosette.available_locales.each do |locale|
|
19
|
+
translation = Manager.read(locale, @key)
|
20
|
+
puts "Translation for #{locale} is: #{translation}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add
|
25
|
+
Rosette.available_locales.each do |locale|
|
26
|
+
puts "Please enter #{locale} translation:"
|
27
|
+
Manager.create(locale, @key, gets.chomp)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove
|
32
|
+
Rosette.available_locales.each do |locale|
|
33
|
+
Manager.delete(locale, @key)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def ask_user_for_key
|
38
|
+
puts 'Please provide the key to translation:'
|
39
|
+
@key = gets.chomp
|
40
|
+
|
41
|
+
normalize_key!
|
42
|
+
end
|
43
|
+
|
44
|
+
def normalize_key!
|
45
|
+
Rosette.available_locales.each do |locale|
|
46
|
+
@key.delete_prefix!("#{locale}.")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def display_help
|
51
|
+
puts <<~HELP
|
52
|
+
Usage: rosette [command]
|
53
|
+
|
54
|
+
Available commands:
|
55
|
+
|
56
|
+
read read translation from available locales
|
57
|
+
add add a translation to available locales
|
58
|
+
remove remove translation from available locales
|
59
|
+
|
60
|
+
For each command you must provide a key pointing to the translation.
|
61
|
+
It can begin with or without the locale. These are all valid keys:
|
62
|
+
|
63
|
+
fr.activemodel.errors.blank
|
64
|
+
en.activemodel.errors.blank
|
65
|
+
activemodel.errors.blank
|
66
|
+
|
67
|
+
HELP
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/rosette/manager.rb
CHANGED
@@ -16,20 +16,24 @@ class Manager
|
|
16
16
|
@keys = normalize "#{locale}.#{key}"
|
17
17
|
@translation = translation
|
18
18
|
end
|
19
|
+
|
20
|
+
def read
|
21
|
+
stored_translations.dig(*@keys)
|
22
|
+
end
|
19
23
|
|
20
24
|
def create
|
21
25
|
new_translation = @keys.reverse.inject(@translation) { |v, k| { k => v } }
|
22
26
|
updated_translations = deep_merge(stored_translations, new_translation)
|
23
27
|
persist(updated_translations)
|
24
|
-
|
25
|
-
|
26
|
-
def read
|
27
|
-
stored_translations.dig(*@keys)
|
28
|
+
|
29
|
+
Manager.normalize!
|
28
30
|
end
|
29
31
|
|
30
32
|
def delete
|
31
33
|
updated_translations = delete_translation(stored_translations, @keys)
|
32
34
|
persist(updated_translations)
|
35
|
+
|
36
|
+
Manager.normalize!
|
33
37
|
end
|
34
38
|
|
35
39
|
def delete_translation(translations, keys)
|
data/lib/rosette/version.rb
CHANGED
data/lib/rosette.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rosette/cli"
|
3
4
|
require "rosette/controller"
|
4
5
|
require "rosette/engine"
|
5
6
|
require "rosette/manager"
|
@@ -10,4 +11,8 @@ require "yaml"
|
|
10
11
|
|
11
12
|
module Rosette
|
12
13
|
mattr_accessor :normalize
|
14
|
+
|
15
|
+
def self.available_locales
|
16
|
+
Rails.configuration.i18n.available_locales.map(&:to_s)
|
17
|
+
end
|
13
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rosette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Platteeuw
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n-tasks
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description: Add missing translations from the interface of your application
|
56
56
|
email:
|
57
57
|
- alexplatteeuw@gmail.com
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- rosette
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -70,8 +71,11 @@ files:
|
|
70
71
|
- app/models/rosette/application_record.rb
|
71
72
|
- app/views/layouts/rosette/application.html.erb
|
72
73
|
- app/views/rosette/new.html.erb
|
74
|
+
- bin/rails
|
75
|
+
- bin/rosette
|
73
76
|
- config/routes.rb
|
74
77
|
- lib/rosette.rb
|
78
|
+
- lib/rosette/cli.rb
|
75
79
|
- lib/rosette/controller.rb
|
76
80
|
- lib/rosette/engine.rb
|
77
81
|
- lib/rosette/manager.rb
|