lit 0.0.4.3 → 0.1.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.
- data/README.md +27 -35
- data/app/assets/javascripts/lit/localizations.js.coffee +8 -1
- data/app/assets/stylesheets/lit/application.css +4 -0
- data/app/controllers/lit/api/v1/base_controller.rb +19 -0
- data/app/controllers/lit/api/v1/locales_controller.rb +14 -0
- data/app/controllers/lit/api/v1/localization_keys_controller.rb +16 -0
- data/app/controllers/lit/api/v1/localizations_controller.rb +18 -0
- data/app/controllers/lit/application_controller.rb +1 -1
- data/app/controllers/lit/incomming_localizations_controller.rb +42 -0
- data/app/controllers/lit/localization_keys_controller.rb +2 -2
- data/app/controllers/lit/localizations_controller.rb +8 -2
- data/app/controllers/lit/sources_controller.rb +60 -0
- data/app/helpers/lit/localizations_helper.rb +1 -1
- data/app/helpers/lit/sources_helper.rb +4 -0
- data/app/models/lit/incomming_localization.rb +60 -0
- data/app/models/lit/locale.rb +3 -2
- data/app/models/lit/localization.rb +33 -3
- data/app/models/lit/localization_key.rb +2 -1
- data/app/models/lit/localization_version.rb +12 -0
- data/app/models/lit/source.rb +87 -0
- data/app/views/layouts/lit/_navigation.html.erb +3 -0
- data/app/views/lit/incomming_localizations/index.html.erb +47 -0
- data/app/views/lit/localization_keys/_localization_row.html.erb +11 -0
- data/app/views/lit/localization_keys/index.html.erb +12 -5
- data/app/views/lit/localizations/_form.html.erb +9 -1
- data/app/views/lit/localizations/_previous_versions_rows.html.erb +15 -0
- data/app/views/lit/localizations/previous_versions.js.erb +3 -0
- data/app/views/lit/localizations/update.js.erb +2 -2
- data/app/views/lit/sources/_form.html.erb +35 -0
- data/app/views/lit/sources/edit.html.erb +6 -0
- data/app/views/lit/sources/index.html.erb +36 -0
- data/app/views/lit/sources/new.html.erb +5 -0
- data/app/views/lit/sources/show.html.erb +18 -0
- data/config/routes.rb +32 -1
- data/db/migrate/20130921071304_create_lit_localization_versions.rb +11 -0
- data/db/migrate/20130923162141_create_lit_sources.rb +12 -0
- data/db/migrate/20130924151910_create_lit_incomming_localizations.rb +21 -0
- data/lib/generators/lit/install/templates/initializer.rb +34 -0
- data/lib/generators/lit/install_generator.rb +73 -0
- data/lib/lit.rb +2 -0
- data/lib/lit/adapters/hash_storage.rb +2 -2
- data/lib/lit/adapters/redis_storage.rb +25 -5
- data/lib/lit/cache.rb +30 -22
- data/lib/lit/i18n_backend.rb +9 -7
- data/lib/lit/version.rb +1 -1
- metadata +42 -2
data/README.md
CHANGED
@@ -4,63 +4,55 @@
|
|
4
4
|
Translate your apps with pleasure (sort of...) and for free. It's simple i18n
|
5
5
|
web interface, build on top of twitter bootstrap, that one may find helpful in
|
6
6
|
translating app by non-technicals.
|
7
|
-
It's still under heave development!
|
8
7
|
|
9
8
|
Highly inspired by Copycopter by thoughtbot.
|
10
9
|
|
10
|
+
### Features
|
11
|
+
|
12
|
+
1. Runs with your app - no need for external services
|
13
|
+
2. Support for array types, (ie. `date.abbr_day_names`)
|
14
|
+
3. Versioning translations - you can always check, how value did look like in past
|
15
|
+
4. Possibility to synchronize between environments or even apps
|
16
|
+
5. Easy to install - works as an engine, comes with simple generator
|
17
|
+
6. You can always export all translations to plain old YAML file
|
18
|
+
|
11
19
|
### Screenshots
|
12
20
|
|
13
21
|
Check wiki: [Screenshots](https://github.com/prograils/lit/wiki/Screenshots)
|
14
22
|
|
15
|
-
###
|
23
|
+
### Installation
|
16
24
|
|
17
|
-
1. Add
|
25
|
+
1. Add `lit` gem to your `Gemfile`
|
18
26
|
```ruby
|
19
27
|
gem "lit"
|
20
|
-
|
28
|
+
````
|
21
29
|
|
22
|
-
2.
|
30
|
+
2. run `bundle install`
|
23
31
|
|
24
|
-
3.
|
25
|
-
|
26
|
-
|
27
|
-
```
|
28
|
-
|
29
|
-
4. Last step is initializer, that should be places ie in ```config/initializers/lit.rb```
|
30
|
-
```ruby
|
31
|
-
## Add extra authentication, symbol, that is provided as param to before_filter
|
32
|
-
## Tested with devise, seems to work
|
33
|
-
# Lit.authentication_function = :authenticate_admin!
|
34
|
-
|
35
|
-
## Pass extra options to storage engine
|
36
|
-
## You may find it useful ie. while using redis in shared environment.
|
37
|
-
# Lit.storage_options = { :prefix=>"my_project" }
|
38
|
-
|
39
|
-
## Which storage engine use. Please remember that in production environment
|
40
|
-
## memory is not shared between processes, and hash may not be correct choice
|
41
|
-
## (as changes will not be visible for all processes). But for any production
|
42
|
-
## environment with finished translation, 'hash' is preferred choice.
|
43
|
-
## Possible values: 'redis' or 'hash'
|
44
|
-
Lit.key_value_engine = 'redis'
|
45
|
-
|
46
|
-
## Initialize engine
|
47
|
-
Lit.init
|
48
|
-
```
|
49
|
-
|
50
|
-
5. After doing above and restarting app, point your browser to ```http://app/lit```
|
32
|
+
3. run installation generator `bundle exec rails g lit:install`
|
33
|
+
|
34
|
+
4. After doing above and restarting app, point your browser to ```http://app/lit```
|
51
35
|
|
36
|
+
5. Profit!
|
37
|
+
|
38
|
+
|
39
|
+
You may want to take a look at generated initializer in `config/initializers/lit.rb` and change some default configuration options.
|
52
40
|
|
53
41
|
|
54
42
|
### ToDo
|
55
43
|
|
44
|
+
* ~~Versioning~~
|
45
|
+
* ~~API~~
|
46
|
+
* ~~Synchronization between environments~~
|
56
47
|
* Rewrite initializer
|
57
48
|
* Rewrite exporter (which is now code from copycopter)
|
58
|
-
* Support for array types (ie.
|
49
|
+
* ~~Support for array types (ie. `date.abbr_day_names`)~~
|
50
|
+
* ~~Generator~~
|
59
51
|
* Support for wysiwyg
|
60
52
|
* Better cache
|
61
|
-
* Support for other key value providers (ie. Redis does not support Array types in easy way)
|
53
|
+
* ~~Support for other key value providers (ie. Redis does not support Array types in easy way)~~ (not applicable, as array storage works now with redis).
|
62
54
|
* Integration with ActiveAdmin
|
63
|
-
|
55
|
+
|
64
56
|
|
65
57
|
### License
|
66
58
|
|
@@ -1,6 +1,8 @@
|
|
1
|
+
@edited_rows = {}
|
1
2
|
$(document).ready ->
|
2
3
|
$('td.localization_row[data-editing=0]').on 'click', ->
|
3
4
|
$this = $(this)
|
5
|
+
edited_rows[$this.data('id')] = $this.html()
|
4
6
|
unless parseInt($this.data('editing'))
|
5
7
|
$this.data('editing', '1')
|
6
8
|
$.get $this.data('edit')
|
@@ -9,6 +11,11 @@ $(document).ready ->
|
|
9
11
|
if $this[0].localName=='button'
|
10
12
|
$this = $this.parents('td.localization_row')
|
11
13
|
$this.data('editing', 0)
|
12
|
-
$this.html $this.data('
|
14
|
+
$this.html edited_rows[$this.data('id')]
|
13
15
|
e.preventDefault()
|
14
16
|
false
|
17
|
+
$('tr.localization_versions_row').on 'click', '.close_versions', (e)->
|
18
|
+
$this = $(this)
|
19
|
+
$parent = $this.parents('tr.localization_versions_row')
|
20
|
+
$parent.addClass('hidden')
|
21
|
+
$parent.children('td').html('')
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Lit
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class BaseController < ActionController::Base
|
5
|
+
layout nil
|
6
|
+
respond_to :json
|
7
|
+
before_filter :authenticate_requests!
|
8
|
+
|
9
|
+
|
10
|
+
private
|
11
|
+
def authenticate_requests!
|
12
|
+
authenticate_or_request_with_http_token do |token, options|
|
13
|
+
Lit.api_key == token
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_dependency "lit/api/v1/base_controller"
|
2
|
+
|
3
|
+
module Lit
|
4
|
+
module Api
|
5
|
+
module V1
|
6
|
+
class LocalesController < Api::V1::BaseController
|
7
|
+
def index
|
8
|
+
@locales = Locale.all
|
9
|
+
render :json=>@locales.as_json(:root=>false, :only=>[:id, :locale])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_dependency "lit/api/v1/base_controller"
|
2
|
+
|
3
|
+
module Lit
|
4
|
+
class Api::V1::LocalizationKeysController < Api::V1::BaseController
|
5
|
+
def index
|
6
|
+
@localization_keys = LocalizationKey
|
7
|
+
if params[:after].present?
|
8
|
+
@localization_keys = @localization_keys.after(DateTime.parse(params[:after])).to_a
|
9
|
+
else
|
10
|
+
@localization_keys = @localization_keys.all
|
11
|
+
end
|
12
|
+
render :json=>@localization_keys.as_json(:root=>false, :only=>[:id, :localization_key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Lit
|
2
|
+
class Api::V1::LocalizationsController < Api::V1::BaseController
|
3
|
+
def index
|
4
|
+
@localizations = Localization
|
5
|
+
if params[:after].present?
|
6
|
+
@localizations = @localizations.after(DateTime.parse(params[:after])).to_a
|
7
|
+
else
|
8
|
+
@localizations = @localizations.all
|
9
|
+
end
|
10
|
+
render :json=>@localizations.as_json(:root=>false, :only=>[:id, :localization_key_id, :locale_id], :methods=>[:value, :localization_key_str, :locale_str])
|
11
|
+
end
|
12
|
+
|
13
|
+
def last_change
|
14
|
+
@localization = Localization.order('updated_at DESC').first
|
15
|
+
render :json=>@localization.as_json(:root=>false, :only=>[], :methods=>[:last_change])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_dependency "lit/application_controller"
|
2
|
+
|
3
|
+
module Lit
|
4
|
+
class IncommingLocalizationsController < ApplicationController
|
5
|
+
before_filter :find_source
|
6
|
+
|
7
|
+
def index
|
8
|
+
@incomming_localizations = @source.incomming_localizations.all
|
9
|
+
end
|
10
|
+
|
11
|
+
def accept
|
12
|
+
@incomming_localization = @source.incomming_localizations.find(params[:id].to_i)
|
13
|
+
@incomming_localization.accept
|
14
|
+
Lit.init.cache.refresh_key @incomming_localization.full_key
|
15
|
+
redirect_to :back
|
16
|
+
end
|
17
|
+
|
18
|
+
def accept_all
|
19
|
+
@source.incomming_localizations.each do |li|
|
20
|
+
li.accept
|
21
|
+
Lit.init.cache.refresh_key li.full_key
|
22
|
+
end
|
23
|
+
redirect_to :back
|
24
|
+
end
|
25
|
+
|
26
|
+
def reject_all
|
27
|
+
@source.incomming_localizations.destroy_all
|
28
|
+
redirect_to :back
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
@incomming_localization = @source.incomming_localizations.find(params[:id].to_i)
|
33
|
+
@incomming_localization.destroy
|
34
|
+
redirect_to source_incomming_localizations_path(@source)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def find_source
|
39
|
+
@source = Source.find(params[:source_id].to_i)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -17,14 +17,14 @@ module Lit
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def star
|
20
|
-
@localization_key = LocalizationKey.find params[:id]
|
20
|
+
@localization_key = LocalizationKey.find params[:id].to_i
|
21
21
|
@localization_key.is_starred = ! @localization_key.is_starred?
|
22
22
|
@localization_key.save
|
23
23
|
respond_to :js
|
24
24
|
end
|
25
25
|
|
26
26
|
def destroy
|
27
|
-
@localization_key = LocalizationKey.find params[:id]
|
27
|
+
@localization_key = LocalizationKey.find params[:id].to_i
|
28
28
|
@localization_key.destroy
|
29
29
|
I18n.backend.available_locales.each do |l|
|
30
30
|
Lit.init.cache.delete_key "#{l}.#{@localization_key.localization_key}"
|
@@ -12,6 +12,12 @@ module Lit
|
|
12
12
|
if @localization.update_attributes(clear_params)
|
13
13
|
Lit.init.cache.refresh_key @localization.full_key
|
14
14
|
end
|
15
|
+
@localization.reload
|
16
|
+
respond_to :js
|
17
|
+
end
|
18
|
+
|
19
|
+
def previous_versions
|
20
|
+
@versions = @localization.versions.order('created_at DESC')
|
15
21
|
respond_to :js
|
16
22
|
end
|
17
23
|
|
@@ -25,8 +31,8 @@ module Lit
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def clear_params
|
28
|
-
if ::
|
29
|
-
params
|
34
|
+
if defined?(::ActionController::StrongParameters)
|
35
|
+
params.require(:localization).permit(:translated_value, :locale_id)
|
30
36
|
else
|
31
37
|
params[:localization]
|
32
38
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_dependency "lit/application_controller"
|
2
|
+
|
3
|
+
module Lit
|
4
|
+
class SourcesController < ApplicationController
|
5
|
+
def index
|
6
|
+
@sources = Source.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
@source = Source.find(params[:id])
|
11
|
+
end
|
12
|
+
|
13
|
+
def new
|
14
|
+
@source = Source.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit
|
18
|
+
@source = Source.find(params[:id])
|
19
|
+
end
|
20
|
+
|
21
|
+
def synchronize
|
22
|
+
@source = Source.find(params[:id])
|
23
|
+
@source.synchronize
|
24
|
+
redirect_to lit.source_incomming_localizations_path(@source)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
@source = Source.new(clear_params)
|
29
|
+
if @source.save
|
30
|
+
redirect_to @source, :notice => 'Source was successfully created.'
|
31
|
+
else
|
32
|
+
render :action => "new"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def update
|
37
|
+
@source = Source.find(params[:id])
|
38
|
+
if @source.update_attributes(clear_params)
|
39
|
+
redirect_to @source, :notice => 'Source was successfully updated.'
|
40
|
+
else
|
41
|
+
render :action => "edit"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
@source = Source.find(params[:id])
|
47
|
+
@source.destroy
|
48
|
+
redirect_to sources_url
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def clear_params
|
53
|
+
if defined?(::ActionController::StrongParameters)
|
54
|
+
params.require(:source).permit(:identifier, :url, :api_key)
|
55
|
+
else
|
56
|
+
params[:source]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Lit
|
2
|
+
class IncommingLocalization < ActiveRecord::Base
|
3
|
+
serialize :translated_value
|
4
|
+
|
5
|
+
## ASSOCIATIONS
|
6
|
+
belongs_to :locale
|
7
|
+
belongs_to :localization_key
|
8
|
+
belongs_to :localization
|
9
|
+
belongs_to :source
|
10
|
+
|
11
|
+
unless defined?(::ActionController::StrongParameters)
|
12
|
+
attr_accessible
|
13
|
+
end
|
14
|
+
|
15
|
+
## BEFORE & AFTER
|
16
|
+
before_create :set_localization_id
|
17
|
+
|
18
|
+
|
19
|
+
def get_value
|
20
|
+
self.translated_value
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_key
|
24
|
+
[self.locale_str, self.localization_key_str].join('.')
|
25
|
+
end
|
26
|
+
|
27
|
+
def accept
|
28
|
+
if self.localization.present?
|
29
|
+
self.localization.translated_value = self.translated_value
|
30
|
+
self.localization.save
|
31
|
+
else
|
32
|
+
unless self.locale.present?
|
33
|
+
self.locale = Lit::Locale.new
|
34
|
+
self.locale.locale = self.locale_str
|
35
|
+
self.locale.save
|
36
|
+
end
|
37
|
+
unless self.localization_key.present?
|
38
|
+
self.localization_key = Lit::LocalizationKey.new
|
39
|
+
self.localization_key.localization_key = self.localization_key_str
|
40
|
+
self.localization_key.save
|
41
|
+
end
|
42
|
+
unless self.localization.present?
|
43
|
+
self.localization = Lit::Localization.new
|
44
|
+
self.localization.locale = self.locale
|
45
|
+
self.localization.localization_key = self.localization_key
|
46
|
+
self.localization.default_value = self.translated_value
|
47
|
+
self.localization.save
|
48
|
+
end
|
49
|
+
end
|
50
|
+
self.destroy
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def set_localization_id
|
55
|
+
if self.locale.present? and self.localization_key.present?
|
56
|
+
self.localization = self.localization_key.localizations.where(:locale_id=>self.locale_id).first
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/app/models/lit/locale.rb
CHANGED
@@ -13,7 +13,7 @@ module Lit
|
|
13
13
|
:presence=>true,
|
14
14
|
:uniqueness=>true
|
15
15
|
|
16
|
-
|
16
|
+
unless defined?(::ActionController::StrongParameters)
|
17
17
|
## ACCESSIBLE
|
18
18
|
attr_accessible :locale
|
19
19
|
end
|
@@ -23,7 +23,8 @@ module Lit
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def get_translated_percentage
|
26
|
-
|
26
|
+
total = self.get_all_localizations_count
|
27
|
+
total > 0 ? (self.get_changed_localizations_count * 100 / total) : 0
|
27
28
|
end
|
28
29
|
|
29
30
|
def get_changed_localizations_count
|