kakimasu 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +31 -0
- data/.travis.yml +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +135 -0
- data/Rakefile +6 -0
- data/app/controllers/kakimasu/home_controller.rb +18 -0
- data/app/controllers/kakimasu/keys_controller.rb +89 -0
- data/app/controllers/kakimasu/translations_controller.rb +37 -0
- data/app/helpers/counting_helper.rb +11 -0
- data/app/helpers/formatting_helper.rb +6 -0
- data/app/helpers/grouping_helper.rb +11 -0
- data/app/helpers/pagination_helper.rb +15 -0
- data/app/helpers/search_key_helper.rb +66 -0
- data/app/helpers/search_translations_helper.rb +101 -0
- data/app/models/translation.rb +2 -0
- data/app/policies/translation_policy.rb +9 -0
- data/app/views/kakimasu/home/index.html.erb +35 -0
- data/app/views/kakimasu/keys/create.js.erb +1 -0
- data/app/views/kakimasu/keys/index.html.erb +183 -0
- data/app/views/kakimasu/shared/_navbar.html.erb +15 -0
- data/app/views/kakimasu/translations/create.js.erb +1 -0
- data/app/views/kakimasu/translations/index.html.erb +168 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/initializers/i18n.rb +58 -0
- data/config/initializers/i18n_backend.rb +5 -0
- data/config/locales/en.yml +34 -0
- data/config/routes.rb +10 -0
- data/kakimasu.gemspec +49 -0
- data/lib/generators/kakimasu/backup_generator.rb +101 -0
- data/lib/generators/kakimasu/policy_generator.rb +18 -0
- data/lib/generators/kakimasu/restore_backup_generator.rb +89 -0
- data/lib/generators/kakimasu/views_generator.rb +22 -0
- data/lib/kakimasu.rb +11 -0
- data/lib/kakimasu/engine.rb +3 -0
- data/lib/kakimasu/version.rb +3 -0
- data/vendor/assets/javascripts/components/activation_button.coffee +10 -0
- data/vendor/assets/javascripts/components/modal.coffee +48 -0
- data/vendor/assets/javascripts/components/translate.coffee +93 -0
- data/vendor/assets/javascripts/components/translation_key_table.coffee +5 -0
- data/vendor/assets/javascripts/components/translation_navigation.coffee +13 -0
- data/vendor/assets/javascripts/components/translation_panel_table.coffee +5 -0
- data/vendor/assets/javascripts/components/translation_percent_chart.coffee +39 -0
- data/vendor/assets/javascripts/components/translation_popover.coffee +90 -0
- data/vendor/assets/javascripts/jquery/jquery.circliful.min.js +1 -0
- data/vendor/assets/javascripts/kakimasu.coffee +18 -0
- data/vendor/assets/stylesheets/circliful.scss +38 -0
- data/vendor/assets/stylesheets/components/_homepage.scss +17 -0
- data/vendor/assets/stylesheets/components/_key_management.scss +53 -0
- data/vendor/assets/stylesheets/components/_navbar.scss +52 -0
- data/vendor/assets/stylesheets/components/_translate_modal.scss +36 -0
- data/vendor/assets/stylesheets/components/_translation_panel.scss +31 -0
- data/vendor/assets/stylesheets/components/_translation_popover.scss +31 -0
- data/vendor/assets/stylesheets/font-awesome/HELP-US-OUT.txt +7 -0
- data/vendor/assets/stylesheets/font-awesome/css/font-awesome.css +2337 -0
- data/vendor/assets/stylesheets/font-awesome/css/font-awesome.min.css +4 -0
- data/vendor/assets/stylesheets/font-awesome/fonts/FontAwesome.otf +0 -0
- data/vendor/assets/stylesheets/font-awesome/fonts/fontawesome-webfont.eot +0 -0
- data/vendor/assets/stylesheets/font-awesome/fonts/fontawesome-webfont.svg +2671 -0
- data/vendor/assets/stylesheets/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/stylesheets/font-awesome/fonts/fontawesome-webfont.woff +0 -0
- data/vendor/assets/stylesheets/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
- data/vendor/assets/stylesheets/font-awesome/less/animated.less +34 -0
- data/vendor/assets/stylesheets/font-awesome/less/bordered-pulled.less +25 -0
- data/vendor/assets/stylesheets/font-awesome/less/core.less +12 -0
- data/vendor/assets/stylesheets/font-awesome/less/fixed-width.less +6 -0
- data/vendor/assets/stylesheets/font-awesome/less/font-awesome.less +18 -0
- data/vendor/assets/stylesheets/font-awesome/less/icons.less +789 -0
- data/vendor/assets/stylesheets/font-awesome/less/larger.less +13 -0
- data/vendor/assets/stylesheets/font-awesome/less/list.less +19 -0
- data/vendor/assets/stylesheets/font-awesome/less/mixins.less +60 -0
- data/vendor/assets/stylesheets/font-awesome/less/path.less +15 -0
- data/vendor/assets/stylesheets/font-awesome/less/rotated-flipped.less +20 -0
- data/vendor/assets/stylesheets/font-awesome/less/screen-reader.less +5 -0
- data/vendor/assets/stylesheets/font-awesome/less/stacked.less +20 -0
- data/vendor/assets/stylesheets/font-awesome/less/variables.less +800 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_animated.scss +34 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_bordered-pulled.scss +25 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_core.scss +12 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_fixed-width.scss +6 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_icons.scss +789 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_larger.scss +13 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_list.scss +19 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_mixins.scss +60 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_path.scss +15 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_rotated-flipped.scss +20 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_screen-reader.scss +5 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_stacked.scss +20 -0
- data/vendor/assets/stylesheets/font-awesome/scss/_variables.scss +800 -0
- data/vendor/assets/stylesheets/font-awesome/scss/font-awesome.scss +18 -0
- data/vendor/assets/stylesheets/kakimasu.scss +35 -0
- metadata +364 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 19f3ecf83f6bda640b5d8465e3ba4b3e3f8fbf32
|
4
|
+
data.tar.gz: c3c2d993b0e079f8aea10a291687c84488155833
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f5dc350f79bc2d2552e6ccda603efde4da8d0306d81f9de269373937d732e8e328d773a1381d455af8687b9e781292c9da34b48db3b9cddd01abbb460f8ac66
|
7
|
+
data.tar.gz: 1e33798a2b6bd8cf576bd0cd5e3914eddd52c24746b05519f7eff753697edaa1b878b9c821c6a1371da9219a973973f906a9dd998d2d0a2c4762ab6f50777e7b
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Metrics/BlockLength:
|
2
|
+
Max: 50
|
3
|
+
Exclude:
|
4
|
+
- 'kakimasu.gemspec'
|
5
|
+
|
6
|
+
Metrics/MethodLength:
|
7
|
+
Max: 50
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 200
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Exclude:
|
14
|
+
- 'spec/**/*'
|
15
|
+
- 'test/**/*'
|
16
|
+
- 'lib/**/*'
|
17
|
+
- 'app/**/*'
|
18
|
+
|
19
|
+
Lint/UselessAssignment:
|
20
|
+
Exclude:
|
21
|
+
- 'config/initializers/i18n.rb'
|
22
|
+
|
23
|
+
Metrics/AbcSize:
|
24
|
+
Max: 75
|
25
|
+
|
26
|
+
Metrics/CyclomaticComplexity:
|
27
|
+
Max: 25
|
28
|
+
|
29
|
+
Metrics/PerceivedComplexity:
|
30
|
+
Max: 25
|
31
|
+
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at roberts.groza23@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Roberts Groza
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/RobertsGroza/kakimasu.svg?branch=master)](https://travis-ci.org/RobertsGroza/kakimasu) [![Coverage Status](https://coveralls.io/repos/github/RobertsGroza/kakimasu/badge.svg?branch=master)](https://coveralls.io/github/RobertsGroza/kakimasu?branch=master)
|
2
|
+
|
3
|
+
# Kakimasu
|
4
|
+
|
5
|
+
Kakimasu is _Ruby_ gem for easy translation management in _Ruby on Rails_ projects which uses _Redis server_ for translation storage.
|
6
|
+
Kakimasu most valuable function is that it can add translations right from your browser. That's right - create translations without suffering. With Kakimasu you can add translations more faster and more effective, and it has even google translate support. You want to use 'lazy lookup' keys? With this gem you can do that with ease from 'key management' view.
|
7
|
+
Adding translations are not only function for Kakimasu. You can manage all used keys in project. You can even see just those keys which doesn't have translations in all languages (keys with missing translations). You can easily track your translation progress in project.
|
8
|
+
Also for developers this gem has special features - views generating and policy generating for ability to customize views and permissions.
|
9
|
+
One of the features is backup - you can save all your translations in backup file and you can restore backup (these functions can be very useful when you migrate project and want to keep your translations).
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'kakimasu'
|
17
|
+
```
|
18
|
+
|
19
|
+
I18n should be set up in the project for successful translation
|
20
|
+
|
21
|
+
Include Kakimasu in your application controller and for successfull translation process you have to add ```:set_show_translation_key```:
|
22
|
+
```ruby
|
23
|
+
class ApplicationController < ActionController::Base
|
24
|
+
include Kakimasu
|
25
|
+
before_action :set_show_translation_key
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Edit *default url options* in your application controller to pass
|
30
|
+
show_translation_key param between requests.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
def default_url_options
|
34
|
+
{ show_translation_key: Thread.current[:show_tranlsation_key] }
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
If I18n is included in default url options then:
|
39
|
+
```ruby
|
40
|
+
def default_url_options
|
41
|
+
{ locale: I18n.locale, show_translation_key: Thread.current[:show_translation_key] }.merge(super)
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Require Kakimasu in your application.coffee
|
46
|
+
|
47
|
+
```
|
48
|
+
#= require kakimasu
|
49
|
+
```
|
50
|
+
|
51
|
+
To use stylesheets add this line to your application.scss
|
52
|
+
```
|
53
|
+
@import "kakimasu";
|
54
|
+
```
|
55
|
+
|
56
|
+
Path to kakimasu panel is *translations_path*
|
57
|
+
|
58
|
+
Link for translator activation should be:
|
59
|
+
```
|
60
|
+
#For activation
|
61
|
+
= link_to t('activate_translation_mode'), { show_translation_key: true }, id: 'activate_translation_mode_button'
|
62
|
+
#For deactivation
|
63
|
+
= link_to t('deactivate_translation_mode'), show_translation_key: false
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
## Usage
|
68
|
+
|
69
|
+
### Configuring views
|
70
|
+
|
71
|
+
If you want to customize kakimasu views, you can easily add them to your _app/views_ by typing in console:
|
72
|
+
|
73
|
+
```console $ rails generate kakimasu:views ```
|
74
|
+
|
75
|
+
### Forms
|
76
|
+
|
77
|
+
There is a issue with form default submit buttons because they display span tags as a plain text (thereby javascript can
|
78
|
+
not be executed). So if you want to translate buttons like any other element in project they look like this:
|
79
|
+
|
80
|
+
```erb
|
81
|
+
<%= f.button :button do %>
|
82
|
+
<% t('translation_key') %>
|
83
|
+
<% end %>
|
84
|
+
```
|
85
|
+
|
86
|
+
## Security
|
87
|
+
|
88
|
+
Of course security is very important for this gem. By default translation mode is available just for admin. If you want to customize something. For example give translation permissions to moderator you should overwrite ``` show_translation_key ``` method.
|
89
|
+
In moderator case it would look like this:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
def set_show_translation_key
|
93
|
+
Thread.current[:show_translation_key] = nil
|
94
|
+
return unless current_user.try(:moderator?)
|
95
|
+
Thread.current[:show_translation_key] = (params[:show_translation_key] == 'true').presence
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
If you want to configure policy then you can generate translation policy file by just typing in console:
|
100
|
+
|
101
|
+
```console
|
102
|
+
$ rails generate kakimasu:policy
|
103
|
+
```
|
104
|
+
|
105
|
+
## Backups
|
106
|
+
|
107
|
+
### Create backup
|
108
|
+
|
109
|
+
You can easily create backup file with command:
|
110
|
+
|
111
|
+
```console $ rails generate kakimasu:backup ```
|
112
|
+
|
113
|
+
After backup all translations are stored in file called _.kakimasu_backup.yml_
|
114
|
+
|
115
|
+
### Restore translations
|
116
|
+
|
117
|
+
Command for restoring translations from the backup file:
|
118
|
+
|
119
|
+
```console $ rails generate kakimasu:restore_backup ```
|
120
|
+
|
121
|
+
## Development
|
122
|
+
|
123
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
124
|
+
|
125
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
126
|
+
|
127
|
+
## Contributing
|
128
|
+
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Roberts Groza/kakimasu. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
130
|
+
|
131
|
+
|
132
|
+
## License
|
133
|
+
|
134
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
135
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kakimasu
|
2
|
+
class HomeController < ::ApplicationController
|
3
|
+
# Include neccessary helpers
|
4
|
+
include SearchTranslationsHelper
|
5
|
+
include CountingHelper
|
6
|
+
|
7
|
+
def index
|
8
|
+
# Check if user has permissions
|
9
|
+
authorize :translation, :index?
|
10
|
+
policy_scope(Translation)
|
11
|
+
|
12
|
+
# Get translation percentage
|
13
|
+
@all_keys_count = countKeys(search_for_translations('all_translation_keys'))
|
14
|
+
@missing_translation_keys_count = countKeys(search_for_translations('missing_translations'))
|
15
|
+
@percentage = translationPercentage(@all_keys_count, @missing_translation_keys_count)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Kakimasu
|
2
|
+
class KeysController < ::ApplicationController
|
3
|
+
# Include neccessary helpers
|
4
|
+
include SearchTranslationsHelper
|
5
|
+
include GroupingHelper
|
6
|
+
include SearchKeyHelper
|
7
|
+
include PaginationHelper
|
8
|
+
|
9
|
+
before_action :categories
|
10
|
+
before_action :set_keys_category
|
11
|
+
|
12
|
+
def index
|
13
|
+
# Check if user has permissions
|
14
|
+
authorize :translation, :index?
|
15
|
+
policy_scope(Translation)
|
16
|
+
|
17
|
+
set_page_size(5) # set number of keys in one page
|
18
|
+
params[:page] = 1 unless params[:page] # if page number is not stated, then by default it is 1. page
|
19
|
+
@keys = search_for_translations(@category) # search for used keys
|
20
|
+
@active_tab = 'keys' # sets active tab in navigation
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
# Authorize user
|
25
|
+
authorize :translation, :create?
|
26
|
+
|
27
|
+
before_key = params[:key] # Varibale contains key before create method was executed
|
28
|
+
|
29
|
+
# Check if path to translation key is given
|
30
|
+
enable_lazy_lookup unless params[:path].blank?
|
31
|
+
|
32
|
+
# Variable which is true when function saves changes of something.
|
33
|
+
changed = false
|
34
|
+
|
35
|
+
# Save entered translations
|
36
|
+
I18n.available_locales.each do |l|
|
37
|
+
params[l].gsub!("'", "'") # Substitutes quotes with quotes HTML code.
|
38
|
+
|
39
|
+
# If there is translation which is not equal with old one, then it is saved
|
40
|
+
unless params[l].blank? || I18n.t(params[:key], locale: l) == params[l]
|
41
|
+
changed = true if (I18n.backend.store_translations(l, { params[:key] => params[l] }, escape: false))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
I18n.backend.store_translations(params[:language], { params[:key] => params[:value] }, escape: false) if params[:language]
|
45
|
+
|
46
|
+
# Process ajax process diferently
|
47
|
+
if request.xhr?
|
48
|
+
respond_to do |format|
|
49
|
+
format.js {}
|
50
|
+
end
|
51
|
+
else
|
52
|
+
redirect_to kakimasu_keys_path(keys_category: @category)
|
53
|
+
end
|
54
|
+
|
55
|
+
# If the key is changed then it means there were changes
|
56
|
+
changed = true if before_key != params[:key]
|
57
|
+
|
58
|
+
# Shows result to user
|
59
|
+
if changed
|
60
|
+
flash.notice = t('translation_succesfully_stored')
|
61
|
+
else
|
62
|
+
flash.alert = t('nothing_was_changed')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# All available categories in "key management" view
|
69
|
+
def categories
|
70
|
+
@categories = ['missing_translations', 'all_translation_keys', 'active_record_attribute_translations', 'active_record_model_translations']
|
71
|
+
end
|
72
|
+
|
73
|
+
# Set current category
|
74
|
+
def set_keys_category
|
75
|
+
@category = params[:keys_category] || 'missing_translations'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Enable/disable 'lazy lookup' on key based on checkbox 'unique' value
|
79
|
+
def enable_lazy_lookup
|
80
|
+
if params[:lazy_lookup]
|
81
|
+
lazy_lookup_key(params[:key], params[:path])
|
82
|
+
params[:key] = prefix(params[:path]) + '.' + params[:key] unless params[:key].start_with?(prefix(params[:path]))
|
83
|
+
else
|
84
|
+
remove_lazy_lookup(params[:key], params[:path])
|
85
|
+
params[:key] = params[:key].split('.').last
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Kakimasu
|
2
|
+
class TranslationsController < ::ApplicationController
|
3
|
+
# Include neccessary helpers
|
4
|
+
include PaginationHelper
|
5
|
+
|
6
|
+
def index
|
7
|
+
# Authorization
|
8
|
+
authorize :translation, :index?
|
9
|
+
policy_scope(Translation)
|
10
|
+
|
11
|
+
@translations = TRANSLATION_STORE # Gets all translations from redis
|
12
|
+
@grouped_keys = @translations.keys.group_by { |key| key.partition('.').last } # Groups all translations by key
|
13
|
+
@active_tab = 'translations' # Sets active tab in navigation
|
14
|
+
|
15
|
+
set_page_size(10) # set number of keys in one page
|
16
|
+
params[:page] = 1 unless params[:page] # if page number is not stated, then by default it is 1. page
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
authorize :translation, :create?
|
21
|
+
I18n.available_locales.each do |l|
|
22
|
+
params[l]&.gsub!("'", "'")
|
23
|
+
I18n.backend.store_translations(l, { params[:key] => params[l] }, escape: false) unless params[l].blank?
|
24
|
+
end
|
25
|
+
params[:value]&.gsub!("'", "'")
|
26
|
+
I18n.backend.store_translations(params[:language], { params[:key] => params[:value] }, escape: false) if params[:language]
|
27
|
+
|
28
|
+
if request.xhr?
|
29
|
+
respond_to do |format|
|
30
|
+
format.js {}
|
31
|
+
end
|
32
|
+
else
|
33
|
+
redirect_to :back
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|