simple_form-magic_submit 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -17
- data/lib/simple_form/magic_submit/version.rb +1 -1
- data/lib/simple_form/magic_submit.rb +9 -3
- data/locales/en.yml +31 -14
- data/locales/ru.yml +31 -14
- metadata +1 -1
data/README.md
CHANGED
@@ -78,34 +78,37 @@ en:
|
|
78
78
|
simple_form:
|
79
79
|
magic_submit:
|
80
80
|
default:
|
81
|
-
|
81
|
+
new:
|
82
82
|
submit: "Create a new %{model}"
|
83
83
|
retry: "Try creating once again"
|
84
84
|
disable_with: "Creating…"
|
85
|
-
|
85
|
+
edit:
|
86
86
|
submit: "Save changes"
|
87
87
|
retry: "Try saving once again"
|
88
88
|
disable_with: "Saving…"
|
89
89
|
cancel:
|
90
90
|
format: "%{submit_button} or %{cancel_link}"
|
91
91
|
cancel: "Cancel"
|
92
|
-
# Replace 'model_name' below with the name of your model and
|
93
|
-
# alter the transaltions as you wish.
|
94
|
-
#
|
95
|
-
# Each translation will have %{model} interpolated.
|
96
|
-
#
|
97
|
-
# model_name:
|
98
|
-
# create:
|
99
|
-
# submit: "Create a new %{model}"
|
100
|
-
# retry: "Try creating once again"
|
101
|
-
# disable_with: "Creating…"
|
102
|
-
# save:
|
103
|
-
# submit: "Save changes"
|
104
|
-
# retry: "Try saving once again"
|
105
|
-
# disable_with: "Saving…"
|
106
92
|
```
|
107
93
|
|
108
|
-
Simply copy the file to you config/locales folder inside your Rails project if you want to change the default strings.
|
94
|
+
Simply copy the file to you `config/locales` folder inside your Rails project if you want to change the default strings.
|
95
|
+
|
96
|
+
Say, for the title the keys will be looked up in the following order:
|
97
|
+
|
98
|
+
1. `simple_form.magic_submit.namespace_name.controller_name.model_name.action.submit`
|
99
|
+
2. `simple_form.magic_submit.namespace_name.controller_name.action.submit`
|
100
|
+
3. `simple_form.magic_submit.default.action.submit`
|
101
|
+
4. `helpers.submit.action`
|
102
|
+
|
103
|
+
Say, for a `Admin::UsersController` and a `Roles` model, the following lookups will be
|
104
|
+
made on the edit action:
|
105
|
+
|
106
|
+
1. `simple_form.magic_submit.admin.users.roles.edit.submit`
|
107
|
+
2. `simple_form.magic_submit.admin.users.edit.submit`
|
108
|
+
3. `simple_form.magic_submit.default.edit.submit`
|
109
|
+
4. `helpers.submit.edit`
|
110
|
+
|
111
|
+
Each lookup will have `%{model}` interpolated to the name of the model.
|
109
112
|
|
110
113
|
## To-do
|
111
114
|
|
@@ -22,16 +22,22 @@ module SimpleForm
|
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
|
+
def controller_scope
|
26
|
+
template.controller.params[:controller].gsub('/', '.')
|
27
|
+
end
|
25
28
|
|
26
29
|
def object_scope
|
27
30
|
self.object.class.model_name.underscore
|
28
31
|
end
|
29
32
|
|
30
33
|
def translate_key(key = nil)
|
31
|
-
op = self.object.new_record? ? :create : :save
|
32
34
|
key ||= self.object.errors.count > 0 ? :retry : :submit
|
33
|
-
I18n.t("simple_form.magic_submit.#{object_scope}.#{
|
34
|
-
default: [
|
35
|
+
I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
|
36
|
+
default: [
|
37
|
+
:"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
|
38
|
+
:"simple_form.magic_submit.default.#{lookup_action}.#{key}",
|
39
|
+
:"helpers.submit.#{lookup_action}"
|
40
|
+
],
|
35
41
|
model: self.object.class.model_name.titlecase
|
36
42
|
).html_safe
|
37
43
|
end
|
data/locales/en.yml
CHANGED
@@ -2,28 +2,45 @@ en:
|
|
2
2
|
simple_form:
|
3
3
|
magic_submit:
|
4
4
|
default:
|
5
|
-
|
5
|
+
new:
|
6
6
|
submit: "Create a new %{model}"
|
7
7
|
retry: "Try creating once again"
|
8
8
|
disable_with: "Creating…"
|
9
|
-
|
9
|
+
edit:
|
10
10
|
submit: "Save changes"
|
11
11
|
retry: "Try saving once again"
|
12
12
|
disable_with: "Saving…"
|
13
13
|
cancel:
|
14
14
|
format: "%{submit_button} or %{cancel_link}"
|
15
15
|
cancel: "Cancel"
|
16
|
-
# Replace 'model_name' below with
|
17
|
-
# alter the transaltions as you wish.
|
16
|
+
# Replace 'namespace_name', 'controller_name', 'model_name' below with
|
17
|
+
# the name of your model and alter the transaltions as you wish.
|
18
18
|
#
|
19
|
-
#
|
19
|
+
# Say, for the title the keys will be looked up in the following order:
|
20
20
|
#
|
21
|
-
# model_name
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
21
|
+
# 1. simple_form.magic_submit.namespace_name.controller_name.model_name.action.submit
|
22
|
+
# 2. simple_form.magic_submit.namespace_name.controller_name.action.submit
|
23
|
+
# 3. simple_form.magic_submit.default.action.submit
|
24
|
+
# 4. helpers.submit.action
|
25
|
+
#
|
26
|
+
# Say for a Admin::UsersController and a Roles model, the following lookups will be
|
27
|
+
# made on the edit action:
|
28
|
+
#
|
29
|
+
# 1. simple_form.magic_submit.admin.users.roles.edit.submit
|
30
|
+
# 2. simple_form.magic_submit.admin.users.edit.submit
|
31
|
+
# 3. simple_form.magic_submit.default.edit.submit
|
32
|
+
# 4. helpers.submit.edit
|
33
|
+
#
|
34
|
+
# Each lookup will have %{model} interpolated to the name of the model.
|
35
|
+
#
|
36
|
+
# namespace_name:
|
37
|
+
# controller_name:
|
38
|
+
# model_name:
|
39
|
+
# create:
|
40
|
+
# submit: "Create a new %{model}"
|
41
|
+
# retry: "Try creating once again"
|
42
|
+
# disable_with: "Creating…"
|
43
|
+
# save:
|
44
|
+
# submit: "Save changes"
|
45
|
+
# retry: "Try saving once again"
|
46
|
+
# disable_with: "Saving…"
|
data/locales/ru.yml
CHANGED
@@ -2,28 +2,45 @@ ru:
|
|
2
2
|
simple_form:
|
3
3
|
magic_submit:
|
4
4
|
default:
|
5
|
-
|
5
|
+
new:
|
6
6
|
submit: "Сохранить"
|
7
7
|
retry: "Попробовать еще раз"
|
8
8
|
disable_with: "Сохранение…"
|
9
|
-
|
9
|
+
edit:
|
10
10
|
submit: "Сохранить изменения"
|
11
11
|
retry: "Попробовать еще раз"
|
12
12
|
disable_with: "Сохранение…"
|
13
13
|
cancel:
|
14
14
|
format: "%{submit_button} или %{cancel_link}"
|
15
15
|
cancel: "отменить"
|
16
|
-
# Replace 'model_name' below with
|
17
|
-
# alter the transaltions as you wish.
|
16
|
+
# Replace 'namespace_name', 'controller_name', 'model_name' below with
|
17
|
+
# the name of your model and alter the transaltions as you wish.
|
18
18
|
#
|
19
|
-
#
|
19
|
+
# Say, for the title the keys will be looked up in the following order:
|
20
20
|
#
|
21
|
-
# model_name
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
21
|
+
# 1. simple_form.magic_submit.namespace_name.controller_name.model_name.action.submit
|
22
|
+
# 2. simple_form.magic_submit.namespace_name.controller_name.action.submit
|
23
|
+
# 3. simple_form.magic_submit.default.action.submit
|
24
|
+
# 4. helpers.submit.action
|
25
|
+
#
|
26
|
+
# Say for a Admin::UsersController and a Roles model, the following lookups will be
|
27
|
+
# made on the edit action:
|
28
|
+
#
|
29
|
+
# 1. simple_form.magic_submit.admin.users.roles.edit.submit
|
30
|
+
# 2. simple_form.magic_submit.admin.users.edit.submit
|
31
|
+
# 3. simple_form.magic_submit.default.edit.submit
|
32
|
+
# 4. helpers.submit.edit
|
33
|
+
#
|
34
|
+
# Each lookup will have %{model} interpolated to the name of the model.
|
35
|
+
#
|
36
|
+
# namespace_name:
|
37
|
+
# controller_name:
|
38
|
+
# model_name:
|
39
|
+
# create:
|
40
|
+
# submit: "Create a new %{model}"
|
41
|
+
# retry: "Try creating once again"
|
42
|
+
# disable_with: "Creating…"
|
43
|
+
# save:
|
44
|
+
# submit: "Save changes"
|
45
|
+
# retry: "Try saving once again"
|
46
|
+
# disable_with: "Saving…"
|