lit 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,6 +7,8 @@ translating app by non-technicals.
7
7
 
8
8
  Highly inspired by Copycopter by thoughtbot.
9
9
 
10
+ ![travis status](https://travis-ci.org/prograils/lit.svg)
11
+
10
12
  ### Features
11
13
 
12
14
  1. Runs with your app - no need for external services
data/Rakefile CHANGED
@@ -4,6 +4,7 @@ begin
4
4
  rescue LoadError
5
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
+
7
8
  begin
8
9
  require 'rdoc/task'
9
10
  rescue LoadError
@@ -12,6 +13,7 @@ rescue LoadError
12
13
  RDoc::Task = Rake::RDocTask
13
14
  end
14
15
 
16
+
15
17
  RDoc::Task.new(:rdoc) do |rdoc|
16
18
  rdoc.rdoc_dir = 'rdoc'
17
19
  rdoc.title = 'Lit'
@@ -23,13 +25,12 @@ end
23
25
  APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
26
  load 'rails/tasks/engine.rake'
25
27
 
26
-
27
-
28
28
  Bundler::GemHelper.install_tasks
29
29
 
30
30
  require 'rake/testtask'
31
31
 
32
32
  Rake::TestTask.new(:test) do |t|
33
+ puts "Storage: #{ENV['LIT_STORAGE'] || 'redis'}"
33
34
  t.libs << 'lib'
34
35
  t.libs << 'test'
35
36
  t.pattern = 'test/**/*_test.rb'
@@ -37,4 +38,3 @@ Rake::TestTask.new(:test) do |t|
37
38
  end
38
39
 
39
40
 
40
- task :default => :test
@@ -48,3 +48,6 @@ padding: 5px 7px;
48
48
  .well label{
49
49
  font-weight: normal;
50
50
  }
51
+ .localization_row em{
52
+ color: #bbb;
53
+ }
@@ -3,7 +3,7 @@ require_dependency "lit/application_controller"
3
3
  module Lit
4
4
  class DashboardController < ::Lit::ApplicationController
5
5
  def index
6
- @locales = Lit::Locale.ordered
6
+ @locales = Lit::Locale.ordered.visible
7
7
  end
8
8
  end
9
9
  end
@@ -50,6 +50,20 @@ module Lit
50
50
  self.destroy
51
51
  end
52
52
 
53
+ def is_duplicate?(val)
54
+ set_localization_id unless localization.present?
55
+ if localization
56
+ translated_value = localization.read_attribute_before_type_cast('translated_value')
57
+ if localization.is_changed? && !translated_value.nil?
58
+ translated_value == val
59
+ else
60
+ localization.read_attribute_before_type_cast('default_value') == val
61
+ end
62
+ else
63
+ false
64
+ end
65
+ end
66
+
53
67
  private
54
68
  def set_localization_id
55
69
  if self.locale.present? and self.localization_key.present?
@@ -36,7 +36,7 @@ module Lit
36
36
  if result.is_a?(Array)
37
37
  result.each do |r|
38
38
  il = IncommingLocalization.new
39
- if ::Rails::VERSION::MAJOR<4
39
+ if ::Rails::VERSION::MAJOR < 4
40
40
  il = IncommingLocalization.where(:incomming_id=>r["id"]).first_or_initialize
41
41
  else
42
42
  il = IncommingLocalization.find_or_initialize_by(:incomming_id=>r["id"])
@@ -46,20 +46,23 @@ module Lit
46
46
  il.locale = Locale.where(:locale=>il.locale_str).first
47
47
  il.localization_key_str = r["localization_key_str"]
48
48
  il.localization_key = LocalizationKey.where(:localization_key=>il.localization_key_str).first
49
- il.save!
50
- IncommingLocalization.where(:id=>il.id).update_all ['translated_value=?', r["value"]]
49
+ unless il.is_duplicate?(r['value'])
50
+ il.save!
51
+ IncommingLocalization.where(:id=>il.id).
52
+ update_all ['translated_value=?', r["value"]]
53
+ end
51
54
  end
52
- lc = get_last_change
53
- lc = DateTime.parse(lc) unless lc.nil?
54
- touch_last_updated_at(lc)
55
- self.save
55
+ last_change = get_last_change
56
+ last_change = DateTime.parse(last_change) unless last_change.nil?
57
+ touch_last_updated_at(last_change)
58
+ save
56
59
  end
57
60
  end
58
61
  end
59
62
 
60
63
  def touch_last_updated_at!
61
64
  touch_last_updated_at
62
- self.save
65
+ save
63
66
  end
64
67
 
65
68
  private
@@ -1,11 +1,14 @@
1
- <%- la = localization -%>
2
- <% if la.is_a?(Array) %>
1
+ <% if localization.is_a?(Array) %>
3
2
  <ul>
4
- <% la.each do |l| %>
3
+ <% localization.each do |l| %>
5
4
  <li><%= l %></li>
6
5
  <% end %>
7
6
  </ul>
8
7
  <% else %>
9
- <%= la %>
8
+ <% if localization.nil? %>
9
+ <em title="<%= t('.value_not_yet_translated', default: 'Value not yet translated') %>">null</em>
10
+ <% else %>
11
+ <%= localization %>
12
+ <% end %>
10
13
  <% end %>
11
14
 
@@ -22,7 +22,7 @@ Lit.humanize_key = false
22
22
 
23
23
  # Decide if missing translations will fallback to first found translated value
24
24
  # (same key, different language)
25
- Lit.fallback = true
25
+ Lit.fallback = false
26
26
 
27
27
  # API enabled? API allows third party browsing your translations, as well as
28
28
  # synchronizing them between environments
data/lib/lit.rb CHANGED
@@ -16,18 +16,26 @@ module Lit
16
16
  attr_accessor :loader
17
17
  end
18
18
  def self.init
19
- @@table_exists ||= Lit::Locale.table_exists?
19
+ @@table_exists ||= self.check_if_table_exists
20
20
  if self.loader.nil? && @@table_exists
21
21
  self.loader ||= Loader.new
22
- Lit.humanize_key = true if Lit.humanize_key.nil?
23
- #if loading all translations on start, migrations have to be performed
24
- #already, fails on first deploy
25
- #self.loader.cache.load_all_translations
22
+ Lit.humanize_key = false if Lit.humanize_key.nil?
23
+ # if loading all translations on start, migrations have to be already
24
+ # performed, fails on first deploy
25
+ # self.loader.cache.load_all_translations
26
26
  Lit.storage_options ||= {}
27
27
  end
28
28
  self.loader
29
29
  end
30
30
 
31
+ def self.check_if_table_exists
32
+ begin
33
+ Lit::Locale.table_exists?
34
+ rescue
35
+ false
36
+ end
37
+ end
38
+
31
39
  def self.get_key_value_engine
32
40
  case Lit.key_value_engine
33
41
  when 'redis'
@@ -2,7 +2,7 @@ require 'redis'
2
2
  module Lit
3
3
  extend self
4
4
  def redis
5
- $redis = Redis.connect unless $redis
5
+ $redis = Redis.new(url: ENV['REDIS_URL']) unless $redis
6
6
  $redis
7
7
  end
8
8
  class RedisStorage
@@ -82,4 +82,4 @@ module Lit
82
82
  _prefix+"nil_flags:"+key.to_s
83
83
  end
84
84
  end
85
- end
85
+ end
@@ -202,8 +202,9 @@ module Lit
202
202
  end
203
203
  end
204
204
  end
205
- value = key_without_locale.split('.').last.humanize if value.nil? &&
206
- Lit.humanize_key
205
+ if value.nil? && Lit.humanize_key
206
+ value = key_without_locale.split('.').last.humanize
207
+ end
207
208
  end
208
209
  localization.update_default_value(value)
209
210
  end
@@ -20,7 +20,12 @@ module Lit
20
20
  end
21
21
 
22
22
  def available_locales
23
- Lit::Locale.ordered.visible.map{|l| l.locale.to_sym }
23
+ locales = ::Rails.configuration.i18n.available_locales
24
+ if locales and !locales.empty?
25
+ locales
26
+ else
27
+ Lit::Locale.ordered.visible.map{|l| l.locale.to_sym }
28
+ end
24
29
  end
25
30
 
26
31
  # Stores the given translations.
@@ -1,3 +1,3 @@
1
1
  module Lit
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-26 00:00:00.000000000 Z
12
+ date: 2014-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: sass-rails
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>'
52
- - !ruby/object:Gem::Version
53
- version: '3.1'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>'
60
- - !ruby/object:Gem::Version
61
- version: '3.1'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: pg
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -91,22 +75,6 @@ dependencies:
91
75
  - - ! '>='
92
76
  - !ruby/object:Gem::Version
93
77
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: fakeweb
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: '1.3'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: '1.3'
110
78
  description: ! 'Translate your apps with pleasure (sort of...) and for free. It''s
111
79
  simple i18n web interface, build on top of twitter bootstrap, that one may find
112
80
  helpful in translating app by non-technicals. '