t_t 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: d836d08bfcb2cd0c0ddc4cf71c7ff13bc8d95aba
4
- data.tar.gz: 46616d020eef370af7a34e6dd672262be6dcf477
3
+ metadata.gz: 93be7cafdab979b4837cf9be239ecdec38ed2d04
4
+ data.tar.gz: a3bc394c6c54755306a3108e133e4f1f1b5cb24a
5
5
  SHA512:
6
- metadata.gz: 8b0904544cbcce8598217fae39dacc61a7c2940298f9f096a1e24ff36828b06a756fdceef79f01aeafccbc20580ebd49018ee6f72e7a8d52ee0af9db18b4bb91
7
- data.tar.gz: d16e1835b588593536162b9dd9aa5541dcf9ea8bdc672d7de552f172fefdcc8231e354c9435adf85a893f386b3a1f5475bc62e5eeb70a937c4f47db753d958dd
6
+ metadata.gz: b680bb07574bac2214318dd97059757e21a4e7bfae91d6ed32602c828c79cbac1b1ba98e8301e63f35ece020d6a7e5a334dde3da560960df9bb15911dc054355
7
+ data.tar.gz: 789a592362b858ac87dd2e564c8cc33e83e6eeae6a926b5617bad58bc7b75e70386620e9c2b6029a7179ec207a43651a418906a3e0af85d330b775db2629e3f1
data/cheatsheet.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Dos-T cheatsheet
2
2
 
3
3
  ## Commons
4
+
4
5
  The **widely used words** across the application such as "Back", "Cancel", "Save" are the prime candidates to put in **common**:
5
6
 
6
7
  ```ruby
@@ -28,6 +29,54 @@ Time to time there is a need to **override commons** for a section (controller i
28
29
  = tt.c :copy # => "Duplicate"
29
30
  ```
30
31
 
32
+ ## Relative translation
33
+
34
+ Every rails developer is familiar with helper method **#t** which has a magic trick with a dot at the beginning. The
35
+ plug-in has an alternative for it **tt.t(key)** or **tt(key)** which is a little bit simple, faster and has a default
36
+ fallback. Let's look at a common scenario:
37
+
38
+ ```ruby
39
+ # en:
40
+ # blogs:
41
+ # new:
42
+ # help: "The content should not contain a markdown"
43
+
44
+ # app/views/blogs/new.haml
45
+ = t('.help')
46
+
47
+ # with the gem
48
+ = tt(:help)
49
+ ```
50
+
51
+ At the first look there is not a big difference. Until you need to use a same translation in a few controller actions:
52
+ ```ruby
53
+ # en:
54
+ # blogs:
55
+ # new:
56
+ # help: "The content should not contain a markdown"
57
+
58
+ # app/views/blogs/new.haml
59
+ = t('.help')
60
+
61
+ # app/views/blogs/edit.haml
62
+ = t('blogs.new.help')
63
+ ```
64
+
65
+ With Dos-T it's not a case, just put a common translation into `common` sub-key of a controller's translation namespace:
66
+
67
+ ```ruby
68
+ # en:
69
+ # blogs:
70
+ # common:
71
+ # help: "The content should not contain a markdown"
72
+
73
+ # app/views/blogs/new.haml
74
+ = tt(:help)
75
+
76
+ # app/views/blogs/edit.haml
77
+ = tt(:help)
78
+ ```
79
+
31
80
  ## Attributes
32
81
 
33
82
  You probably know that `active_model` based classes have handy method **#human_attribute_name**. The main problems with it are the long method name and `humanization` on translation missing. The gem provides an **almost compatible equivalent #attr**.
@@ -79,6 +128,7 @@ For other `active_model` based orms please specify configuration in an initializ
79
128
  # app/config/tt.rb
80
129
  TT.config(prefix: :mongoid)
81
130
  ```
131
+
82
132
  ## Resources
83
133
 
84
134
  There is another translation hard-to-use feature which are present in `active_model` - **.model_name.human**. It
@@ -0,0 +1,111 @@
1
+ en:
2
+ # view related
3
+ common:
4
+ actions: Actions
5
+ confirm: Are you sure?
6
+ ok: Ok
7
+ export: Export
8
+ import: Import
9
+ more: More
10
+ search: Search
11
+ via: via
12
+ form:
13
+ add: Add
14
+ back: Back
15
+ close: Close
16
+ cancel: Cancel
17
+ change: Change
18
+ copy: Copy
19
+ create: Create
20
+ delete: Delete
21
+ edit: Edit
22
+ save: Save
23
+ select: Select
24
+ update: Update
25
+ upload: Upload
26
+ preview: Preview
27
+ tooltip:
28
+ add_all: Add all
29
+ add_new: Add new
30
+ choose_file: Choose a file
31
+ copy: Copy
32
+ delete: Delete
33
+ edit: Edit
34
+ reset: Reset
35
+ reset_password: Reset password
36
+ update: Update
37
+ view: View
38
+ remove_all: Remove all
39
+
40
+ # resource related
41
+ attributes:
42
+ base:
43
+ created_at: Created at
44
+ description: Description
45
+ email: Email
46
+ first_name: First name
47
+ last_name: Last name
48
+ name: Name
49
+ phone: Phone
50
+ position: Position
51
+ title: Title
52
+ updated_at: Updated at
53
+ user:
54
+ email: Email / Login
55
+ role: User role
56
+ task:
57
+ sort_key: Sort key
58
+ type: Type
59
+ task_list:
60
+ reminders_count: Number of reminders
61
+ tasks_count: Number of tasks
62
+ models:
63
+ icon:
64
+ one: Icon
65
+ other: Icons
66
+ user:
67
+ one: User
68
+ other: Users
69
+ user_group:
70
+ one: User group
71
+ other: User groups
72
+ task:
73
+ one: Task
74
+ other: Tasks
75
+ task_list:
76
+ one: Task list
77
+ other: Task lists
78
+ enums:
79
+ user:
80
+ role:
81
+ ai: Administrator
82
+ ui: Employee
83
+ guest: Guest
84
+ task:
85
+ type:
86
+ reminder: Reminder
87
+ task: Task
88
+
89
+ # error related
90
+ errors:
91
+ messages:
92
+ inclusion: is not included in the list
93
+ exclusion: is reserved
94
+ already_exists: has already been taken
95
+ taken: has already been taken
96
+ user:
97
+ email:
98
+ used: Another user registered with this email
99
+ task:
100
+ task_list_ids:
101
+ blank: Select at least one task list
102
+ # action related
103
+ actions:
104
+ choose_few:
105
+ base: Choose one or more %{rs}
106
+ create:
107
+ base: "The %{r} has been created"
108
+ task: "The %{r} hass been added"
109
+ select_before:
110
+ base: "Please choose a %{r} before"
111
+ icon: "Please choose an %{r} before"
data/lib/t_t.rb CHANGED
@@ -177,8 +177,9 @@ module TT
177
177
  Class.new(Translator, &block)
178
178
  end
179
179
 
180
- def self.config(&block)
181
- Translator.instance_exec(&block)
180
+ def self.config(options = {}, &block)
181
+ Translator.settings(options)
182
+ Translator.instance_exec(&block) if block_given?
182
183
  end
183
184
  end
184
185
 
data/readme.md CHANGED
@@ -89,7 +89,7 @@ The result will be the next:
89
89
 
90
90
  ## Setup
91
91
 
92
- Just add `gem "t_t"` into your Gemfile and run `bundle`.
92
+ Just add `gem "t_t"` into your Gemfile and run `bundle`.
93
93
 
94
94
  ## Requirements
95
95
 
data/t_t.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "t_t"
5
- spec.version = "1.0.0"
5
+ spec.version = "1.0.1"
6
6
  spec.authors = ["Sergey Pchelintsev"]
7
7
  spec.email = ["mail@sergeyp.me"]
8
8
  spec.summary = %q{An opinioned I18n helper}
data/tests/test_helper.rb CHANGED
@@ -3,6 +3,8 @@ require "minitest/mock"
3
3
  require "rack/test"
4
4
  require "action_controller"
5
5
  require "t_t"
6
+ require "t_t/action_factory"
7
+ require "t_t/action_macros"
6
8
 
7
9
  ViewTranslator = TT.fork do
8
10
  lookup_key_method :f, :form
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t_t
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pchelintsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n