rails-i18nterface 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -11
  3. data/Rakefile +13 -2
  4. data/app/controllers/rails_i18nterface/translate_controller.rb +10 -24
  5. data/app/helpers/rails_i18nterface/translate_helper.rb +12 -19
  6. data/app/views/rails_i18nterface/translate/index.html.erb +91 -105
  7. data/config/initializers/missing_translation.rb +4 -2
  8. data/lib/rails-i18nterface.rb +1 -0
  9. data/lib/rails-i18nterface/cache.rb +3 -3
  10. data/lib/rails-i18nterface/keys.rb +21 -11
  11. data/lib/rails-i18nterface/sourcefiles.rb +38 -19
  12. data/lib/rails-i18nterface/translation.rb +34 -0
  13. data/lib/rails-i18nterface/utils.rb +13 -9
  14. data/lib/rails-i18nterface/version.rb +1 -1
  15. data/lib/rails-i18nterface/yamlfile.rb +1 -1
  16. data/spec/controllers/translate_controller_spec.rb +72 -51
  17. data/spec/internal/app/controllers/application_controller.rb +2 -1
  18. data/spec/internal/app/models/article.rb +1 -0
  19. data/spec/internal/db/schema.rb +2 -0
  20. data/spec/internal/log/test.log +0 -2370
  21. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/0PMwId9157j93ZuEBNCPa71HO-BWiCNHuiZtCkqHovk.cache +1 -0
  22. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/172YbT7Y9QCTtQpYWCn3GiUa1XYF30IZjymEsgPF2r4.cache +1 -0
  23. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1RE9Nc-99pz5dq3J_WTniU9ihuoYrOprEnGvyXAa5cY.cache +1 -0
  24. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1vT4QnCK-tMzI13mEL_FMuTrb5BgAdA3XBhVxNv4-r8.cache +1 -0
  25. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/3V-PndZUHey8S35jzCvUM5n8ObasIDurRCq_RlH0jKo.cache +0 -0
  26. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/3l6G7l7GutWzjmS7bo548k2NQXCbu3FuG0RCqtNuUL8.cache +2 -0
  27. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/4vXT_Tqow4flv0JjTjeIZO4MHOerMmqrPSyHiyf3SYE.cache +2 -0
  28. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/7Ki489aXvXh1c80Q1MzMtZpbfnotMDd6A3yHY-HEecw.cache +1 -0
  29. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/9kyHNOVXEDTe7kg34AKp3C9rb7GbxRKGQYV0smgM01I.cache +1 -0
  30. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/DgOE4dVOvx7Kg6yuTxyUSupElQF47xWnXtMcz2TXBaw.cache +2 -0
  31. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/FZqMgA_zpqV7sBthUsaF-loYETVrVCEtlxczLF730GY.cache +1 -0
  32. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/M-S52Jney4p15fjNRm25zSHatM5QqthKsrEU_Q7GTVA.cache +1 -0
  33. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/PaP9vMCDQ63NoJWLaM8fSu0YeRy-eLKbArpgNOm8Z_4.cache +1 -0
  34. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/UHhQ3Te4YSyiy1iqqTRt4nt2dyXqSXxkwAkjepufrsY.cache +2 -0
  35. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/VOKFuKrh87uBuA6qI4LzN8vVjP5mXjzL0j-iaq5sNNg.cache +2 -0
  36. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/Vjw0tPMcLKXFR62wwfemKkM4UCNkbPeERe-8KqFrez0.cache +0 -0
  37. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/YGEo5ly-YOZRgLRVZp1HmXC1FVjMcAWo8Pc006mVUEc.cache +0 -0
  38. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/_RHrJ0guSCf-x6bLKcowvNq4a-4N5p1m_5Abxsef-Zw.cache +0 -0
  39. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/bZt89CxopsDo8--1TGPUMLxKV-mDvRqFMTNNZOfnN08.cache +0 -0
  40. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/frFXg-urENHAZ5rXQ1GpQfRRjJu9Fp_-RvTvn9UugJc.cache +0 -0
  41. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/gaOEShTR6QyHBz9Pv5Ylz1vVWcNP7Dz2DRcuDIl52cs.cache +3 -0
  42. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/mr2V_uFvIXsHQ7VrC70TymoM9CO0RMKHzQgBkn3deHw.cache +1 -0
  43. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/nbwa8EHOBiuE0pKOTtnWN0gAQOC27loObjVaVMX_wZE.cache +0 -0
  44. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/oQxOm6wUSyQ0jKnI8eKFRJLgEQ-dFvxofYtnbn-haqA.cache +1 -0
  45. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/v6huIOApjM-My2aA3RhSsO6U2my-O0Ht7A0lo0YKqPI.cache +2 -0
  46. data/spec/internal/tmp/translation_strings +2 -1
  47. data/spec/lib/cache_spec.rb +32 -29
  48. data/spec/lib/keys_spec.rb +77 -66
  49. data/spec/lib/sourcefiles_spec.rb +53 -50
  50. data/spec/lib/utils_spec.rb +55 -29
  51. data/spec/lib/yamlfile_spec.rb +2 -2
  52. data/spec/requests/search_spec.rb +4 -4
  53. data/spec/selenium/nav_spec.rb +23 -0
  54. data/spec/selenium/sauce.rb +68 -0
  55. data/spec/selenium/translation_spec.rb +19 -0
  56. data/spec/spec_helper.rb +19 -18
  57. metadata +225 -74
  58. data/app/helpers/rails_i18nterface/application_helper.rb +0 -6
  59. data/config/initializers/rails_i18nterface/missing_translation.rb +0 -13
  60. data/spec/internal/app/views/categories/category.erb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeb4d1740a7368ee270f9f502b2644c2a6146ef5
4
- data.tar.gz: ba8719e7acfc76dbe813dc6111638a721f4ad884
3
+ metadata.gz: 741fb9cf5e4fdabfc051baa4c2b43ca5f04a7201
4
+ data.tar.gz: ca9b5b7425033c98dccbdb44d1d4d331e1df7d5a
5
5
  SHA512:
6
- metadata.gz: 0eb51763b0fd7d65122e5a6a3e39fbafc78d17dbf441a732258f84d4c461eff309e4d04fd275c6e6d91b0be4a1d744b292c19aec13d3f8e44b307e48d0b69914
7
- data.tar.gz: 364ca7bbf0d33d75c717c83590a3d4a1ee4219644bca8e51220249ea3c2d62d0030d1bb8feb821dbac1c20807b07f8dbc116c1e2bacd0fa54bb760c4a3024c89
6
+ metadata.gz: 7b5dc47ecb71caa7d6342cbdf9d2ff26b6febbbf1468decb2035745a3a18fb0aa9d41df62a51524483d727b99d83e0dc3a5e01986efdb68b99eb9dbc487c1837
7
+ data.tar.gz: d61684d23f7c064a794126fc329e3df35f1caefda8fc05f01ebd29ee89bdce959fe3fbab606f492ed48a25173ff405e62e42b73a710590b33e6a8976c47a3320
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Rails I18nterface
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rails-i18nterface.png)](http://badge.fury.io/rb/rails-i18nterface)
3
4
  [![Dependency Status](https://gemnasium.com/mose/rails-i18nterface.png)](https://gemnasium.com/mose/rails-i18nterface)
4
5
  [![Build Status](https://secure.travis-ci.org/mose/rails-i18nterface.png?branch=master)](http://travis-ci.org/mose/rails-i18nterface)
5
6
  [![Coverage Status](https://coveralls.io/repos/mose/rails-i18nterface/badge.png?branch=master)](https://coveralls.io/r/mose/rails-i18nterface)
6
7
  [![Code Climate](https://codeclimate.com/github/mose/rails-i18nterface.png)](https://codeclimate.com/github/mose/rails-i18nterface)
7
- [![Gem Version](https://badge.fury.io/rb/rails-i18nterface.png)](http://badge.fury.io/rb/rails-i18nterface)
8
8
 
9
9
  ![rails-i18nterface](http://mose.fr/rails-i18nterface.png)
10
10
 
@@ -61,15 +61,16 @@ Where `[:en]` and `[:ja, :es, :fr]` could be replaced by locale list of your cho
61
61
 
62
62
  ## Todo
63
63
 
64
- * fix the code smell reported by code climate (done)
65
- * extract code from the controller to a lib (dmostly done)
66
- * refactor the libs in a cleaner way (mostly done)
67
- * apply rubocop and follow his law (done)
64
+ * <s>fix the code smell reported by code climate</s> (done)
65
+ * <s>extract code from the controller to a lib</s> (done)
66
+ * <s>refactor the libs in a cleaner way</s> (done)
67
+ * <s>apply rubocop and follow his law</s> (done)
68
+ * <s>remove those damn global variables</s> (done)
69
+ * <s>extend testing to refactored libs</s> (done)
70
+ * add a way in the config to ignore some gem locales
68
71
  * make the application thread-safe
69
- * remove those damn global variables (done)
70
- * extend testing to refactored libs (mostly done)
71
72
  * change navigation to an ajax-driven reload
72
- * add a way to gather .one and .other and .few under same translation line
73
+ * add a way to gather .one and .other and .few under same translation line (not sure actually)
73
74
  * add support for other i18n backends (gettext)
74
75
 
75
76
  ## Note for upgrade 0.1.x to 0.2.x
@@ -104,9 +105,9 @@ Check the [Changelog](https://github.com/mose/rails-i18nterface/blob/master/chan
104
105
  ## License
105
106
 
106
107
  ```
107
- Copyright 2009 Peter Marklund, Joakim Westerlund, Claudius Coenen
108
- Copyright 2011 Larry Sprock, Artin Boghosain, Michal Hantl
109
- Copyright 2013 Mose
108
+ Copyright 2009-2011 Peter Marklund, Joakim Westerlund, Claudius Coenen
109
+ Copyright 2011-2013 Larry Sprock, Artin Boghosain, Michal Hantl
110
+ Copyright 2013-2015 Mose
110
111
 
111
112
  Permission is hereby granted, free of charge, to any person obtaining
112
113
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -11,13 +11,24 @@ require "bundler/gem_tasks"
11
11
 
12
12
  require "rake/testtask"
13
13
 
14
-
15
14
  require "rspec/core/rake_task" # RSpec 2.0
15
+
16
+ desc "launch rspec tests"
16
17
  task :spec do
17
18
  RSpec::Core::RakeTask.new(:spec) do |t|
18
19
  t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
19
- t.pattern = 'spec/**/*_spec.rb'
20
+ t.pattern = 'spec/{controllers,lib,requests}/*_spec.rb'
21
+ end
22
+ end
23
+
24
+ desc "launch selenium tests on SauceLabs"
25
+ task :sauce do
26
+ RSpec::Core::RakeTask.new(:sauce) do |t|
27
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
28
+ t.pattern = 'spec/selenium/*_spec.rb'
20
29
  end
21
30
  end
22
31
 
23
32
  task :default => :spec
33
+
34
+
@@ -2,20 +2,17 @@
2
2
 
3
3
  module RailsI18nterface
4
4
  class TranslateController < RailsI18nterface::ApplicationController
5
-
6
5
  include Utils
7
6
 
8
7
  before_filter :init
9
- before_filter :init_translations
10
8
 
11
9
  def index
12
- @dbvalues = {}
13
10
  @keys = RailsI18nterface::Keys.new(Rails.root, @from_locale, @to_locale)
14
11
  @keys.apply_filters(params)
15
- paginate_keys
12
+ @keys.paginate(@page, @per_page)
16
13
  @total_entries = @keys.all_keys.size
17
14
  @page_title = 'Translate'
18
- @show_filters = ['all', 'untranslated', 'translated']
15
+ @show_filters = %w(all untranslated translated)
19
16
  end
20
17
 
21
18
  def destroy
@@ -25,11 +22,11 @@ module RailsI18nterface
25
22
 
26
23
  def export
27
24
  locale = params[:locale].to_sym
28
- keys = {locale => I18n.backend.send(:translations)[locale] || {}}
25
+ keys = { locale => I18n.backend.send(:translations)[locale] || {} }
29
26
  remove_blanks keys
30
27
  yaml = keys_to_yaml(keys)
31
28
  response.headers['Content-Disposition'] = "attachment; filename=#{locale}.yml"
32
- render :text => yaml
29
+ render text: yaml
33
30
  end
34
31
 
35
32
  def update
@@ -40,7 +37,8 @@ module RailsI18nterface
40
37
  yaml.write_to_file
41
38
  force_init_translations
42
39
  flash[:notice] = 'Translations stored'
43
- redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
40
+ reload
41
+ # redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
44
42
  end
45
43
 
46
44
  def reload
@@ -49,19 +47,7 @@ module RailsI18nterface
49
47
  redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
50
48
  end
51
49
 
52
- private
53
-
54
- def paginate_keys
55
- params[:page] ||= 1
56
- @paginated_keys = @keys.all_keys[offset, @per_page]
57
- end
58
-
59
- def offset
60
- (params[:page].to_i - 1) * @per_page
61
- end
62
-
63
-
64
- protected
50
+ protected
65
51
 
66
52
  def init
67
53
  init_session
@@ -71,14 +57,14 @@ module RailsI18nterface
71
57
  end
72
58
 
73
59
  def init_sort
74
- params[:sort_by] = 'key' unless params[:sort_by]
60
+ params[:sort_by] ||= 'key'
75
61
  end
76
62
 
77
63
  def init_assigns
78
64
  @from_locale = session[:from_locale].to_sym
79
65
  @to_locale = session[:to_locale].to_sym
80
66
  @per_page = session[:per_page]
81
- @sort_by = params[:sort_by] || 'key'
67
+ @page = (params[:page] || 1).to_i
82
68
  end
83
69
 
84
70
  def init_session
@@ -99,4 +85,4 @@ module RailsI18nterface
99
85
  end
100
86
 
101
87
  end
102
- end
88
+ end
@@ -1,11 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module RailsI18nterface
4
- module TranslateHelper
5
4
 
6
- def lookup(locale, key)
7
- I18n.backend.send(:lookup, locale, key)
8
- end
5
+ # various views helpers
6
+ module TranslateHelper
9
7
 
10
8
  def simple_filter(labels, param_name = 'filter')
11
9
  filter = []
@@ -13,23 +11,14 @@ module RailsI18nterface
13
11
  if label.to_s == params[param_name].to_s
14
12
  filter << "<i>#{label}</i>"
15
13
  else
16
- link_params = params.merge({param_name.to_s => label})
17
- link_params.merge!({'page' => nil}) if param_name.to_s != 'page'
14
+ link_params = params.merge(param_name.to_s => label)
15
+ link_params.merge!('page' => nil) if param_name.to_s != 'page'
18
16
  filter << link_to(label, link_params)
19
17
  end
20
18
  end
21
19
  filter.join(' | ')
22
20
  end
23
21
 
24
- def n_lines(text, line_size)
25
- n_lines = 1
26
- if text.present?
27
- n_lines = text.to_s.split("\n").size
28
- n_lines = text.to_s.length / line_size + 1 if n_lines == 1 && text.to_s.length > line_size
29
- end
30
- n_lines
31
- end
32
-
33
22
  def build_namespace(h)
34
23
  out = '<ul>'
35
24
  dirs = {}
@@ -57,11 +46,15 @@ module RailsI18nterface
57
46
  k != '' && k += '.'
58
47
  h.each do |key, val|
59
48
  if val.is_a? Hash
60
- out << '<li class="dir"><span class="display" data-id="%s"></span>%s <span class="num">(%d)</span>' %
61
- [ k + key.to_s, key.to_s, val.length]
49
+ out << sprintf(
50
+ '<li class="dir"><span class="display" data-id="%s"></span>%s <span class="num">(%d)</span>',
51
+ k + key.to_s,
52
+ key.to_s,
53
+ val.length
54
+ )
62
55
  out << list_namespace(k + key.to_s, val)
63
56
  else
64
- out << '<li class="item" data-id="%s">%s' % [ k + key.to_s, key]
57
+ out << sprintf('<li class="item" data-id="%s">%s', k + key.to_s, key)
65
58
  end
66
59
  out << '</li>'
67
60
  end
@@ -69,4 +62,4 @@ module RailsI18nterface
69
62
  end
70
63
 
71
64
  end
72
- end
65
+ end
@@ -1,38 +1,39 @@
1
1
  <%= form_tag(params, :method => :get, :name => 'filter_form') do %>
2
- <%= hidden_field_tag(:filter, params[:filter]) %>
3
- <%= hidden_field_tag(:sort_by, params[:sort_by]) %>
4
- <div id="top">
5
- <h1>
6
- <div class="right">
7
- <%= select_tag(:from_locale, options_for_select(I18n.available_locales, @from_locale.to_sym)) %> <span>to</span>
8
- <%= select_tag(:to_locale, options_for_select(I18n.available_locales, @to_locale.to_sym)) %>
9
- <%= submit_tag "Display" %>
10
- </div>
11
- <%= link_to '.. /', '../' %>
12
- <%= link_to @page_title, root_path %></a>
13
- <div class="center">
14
- <label>Show:</label> <%= simple_filter(@show_filters).html_safe %>
15
- Found <strong><%= @keys.all_keys.size %></strong> messages
16
- <%= link_to "Reload messages", translate_reload_path(params) %>
17
- </div>
18
- </h1>
19
- <% flash.each do |key, msg| %>
20
- <div class="flash" id="<%= key %>"><%= msg %></div>
21
- <% end %>
22
- </div>
23
- <div id="searchbox">
24
- Per page
25
- <%= text_field_tag(:per_page, session[:per_page], size: 2) %>
26
- <%= select_tag(:key_type, options_for_select([["Key contains", 'contains'], ["Key starts with", 'starts_with']], params[:key_type])) %>
27
- <%= text_field_tag(:key_pattern, params[:key_pattern], :size => 50, :id => "key_pattern_value", :class => "text-default") %>
2
+ <%= hidden_field_tag(:filter, params[:filter]) %>
3
+ <%= hidden_field_tag(:sort_by, params[:sort_by]) %>
4
+ <div id="top">
5
+ <h1>
6
+ <div class="right">
7
+ <%= select_tag(:from_locale, options_for_select(I18n.available_locales, @from_locale.to_sym)) %> <span>to</span>
8
+ <%= select_tag(:to_locale, options_for_select(I18n.available_locales, @to_locale.to_sym)) %>
9
+ <%= submit_tag "Display" %>
10
+ </div>
11
+ <%= link_to '.. /', '../' %>
12
+ <%= link_to @page_title, root_path %></a>
13
+ <div class="center">
14
+ <label>Show:</label> <%= simple_filter(@show_filters).html_safe %>
15
+ Found <strong><%= @total_entries %></strong> messages
16
+ <%= link_to "Reload messages", translate_reload_path %>
17
+ <%# link_to "Reload messages", translate_reload_path(params) %>
18
+ </div>
19
+ </h1>
20
+ <% flash.each do |key, msg| %>
21
+ <div class="flash" id="<%= key %>"><%= msg %></div>
22
+ <% end %>
23
+ </div>
24
+ <div id="searchbox">
25
+ <%= text_field_tag(:per_page, session[:per_page], size: 2) %>
26
+ Per page
27
+ <%= select_tag(:key_type, options_for_select([["Key contains", 'contains'], ["Key starts with", 'starts_with']], params[:key_type])) %>
28
+ <%= text_field_tag(:key_pattern, params[:key_pattern], :size => 50, :id => "key_pattern_value", :class => "text-default") %>
28
29
 
29
- <%= select_tag(:text_type, options_for_select([['Text contains','contains'], ['Text equals','equals']], params[:text_type])) %>
30
- <%= text_field_tag(:text_pattern, params[:text_pattern], :size => 50, :id => "text_pattern_value", :class => "text-default") %>
30
+ <%= select_tag(:text_type, options_for_select([['Text contains','contains'], ['Text equals','equals']], params[:text_type])) %>
31
+ <%= text_field_tag(:text_pattern, params[:text_pattern], :size => 50, :id => "text_pattern_value", :class => "text-default") %>
31
32
 
32
33
  <%= link_to "clear", params.merge({:text_pattern => nil, :key_pattern => nil}), class: 'btn' %>
33
34
  <%= submit_tag "Search" %>
34
35
  <%= link_to "Export language file", translate_export_path(:locale => @to_locale), class: 'btn sep' %>
35
- </div>
36
+ </div>
36
37
  <% end %>
37
38
 
38
39
  <div id="namespaces">
@@ -41,94 +42,79 @@
41
42
 
42
43
  <div id="inside">
43
44
  <div class="paging">
44
- <%= render :partial => 'pagination', :locals => {:total_entries => @keys.all_keys.size, :per_page => @per_page} %>
45
+ <%= render :partial => 'pagination', :locals => { :total_entries => @total_entries, :per_page => @per_page } %>
45
46
  </div>
46
47
 
47
- <% if @keys.all_keys.size > 0 %>
48
- <%= form_tag(translate_path, method: :put) do %>
49
- <div>
50
- <%= hidden_field_tag(:filter, params[:filter], :id => "hid_filter") %>
51
- <%= hidden_field_tag(:sort_by, params[:sort_by], :id => "hid_sort_by") %>
52
- <%= hidden_field_tag(:key_type, params[:key_type], :id => "hid_key_type") %>
53
- <%= hidden_field_tag(:key_pattern, params[:key_pattern], :id => "hid_key_pattern") %>
54
- <%= hidden_field_tag(:text_type, params[:text_type], :id => "hid_text_type") %>
55
- <%= hidden_field_tag(:text_pattern, params[:text_pattern], :id => "hid_text_pattern") %>
56
- </div>
57
- <div class="translations">
58
- <p class="translate">
59
- Translations from <b><%= @from_locale %></b> to <b><%= @to_locale %></b> -
60
- <label>Sort by:</label> <%= simple_filter(["key", "text"], 'sort_by').html_safe %>
61
- <%= submit_tag "Save Translations", style: 'float:right;' %>
62
- </p>
63
- <% @paginated_keys.each do |key|
64
- from_text = lookup(@from_locale, key)
65
- to_text = lookup(@to_locale, key)
66
- line_size = 100
67
- n_lines = n_lines(from_text, line_size)
68
- field_name = "key[#{key}]"
69
- tid = key.split('.').join("_")
70
-
71
- %>
72
- <div class="translation">
73
- <p class="edit-form">
74
- <% if n_lines > 1 %>
75
- <div class="right">
76
- <% if @keys.files[key] %>
48
+ <% if @total_entries > 0 %>
49
+ <%= form_tag(translate_path, method: :put) do %>
50
+ <%= hidden_field_tag(:filter, params[:filter], :id => "hid_filter") %>
51
+ <%= hidden_field_tag(:sort_by, params[:sort_by], :id => "hid_sort_by") %>
52
+ <%= hidden_field_tag(:key_type, params[:key_type], :id => "hid_key_type") %>
53
+ <%= hidden_field_tag(:key_pattern, params[:key_pattern], :id => "hid_key_pattern") %>
54
+ <%= hidden_field_tag(:text_type, params[:text_type], :id => "hid_text_type") %>
55
+ <%= hidden_field_tag(:text_pattern, params[:text_pattern], :id => "hid_text_pattern") %>
56
+ <div class="translations">
57
+ <p class="translate">
58
+ Translations from <b><%= @from_locale %></b> to <b><%= @to_locale %></b> -
59
+ <label>Sort by:</label> <%= simple_filter(["key", "text"], 'sort_by').html_safe %>
60
+ <%= submit_tag "Save Translations", style: 'float:right;' %>
61
+ </p>
62
+ <% @keys.translations.each do |tr| %>
63
+ <div class="translation">
64
+ <p class="edit-form">
65
+ <div class="right">
66
+ <% if tr.files %>
77
67
  <div class="files">
78
- <div class="count">found in <%= @keys.files[key].count %> files</div>
68
+ <div class="count">
69
+ found in <%= tr.files.count %> files
70
+ </div>
79
71
  <div class="filelist">
80
- <div><%= @keys.files[key].join("</div><div>").html_safe %></div>
72
+ <div><%= tr.files.join("</div><div>").html_safe %></div>
81
73
  </div>
82
74
  </div>
83
75
  <% end %>
84
- <span class="key"><%=h key %></span>
85
- <a href="#" class="delete" title="Delete this key from database">X</a>
86
- </div>
87
- <div class="long-translation">
88
- <div class="translation-text">
89
- <pre id="<%= tid %>_original"><%= from_text %></pre>
90
- <div class="clear"></div>
91
- </div>
92
- <div class="translation-textarea">
93
- <%= text_area_tag(field_name, to_text, :rows => n_lines, :id => tid) %>
94
- <div class="clear"></div>
95
- </div>
96
- <div class="clear"></div>
97
- </div>
98
- <% else %>
99
- <div class="right">
100
- <% if @keys.files[key] %>
101
- <div class="files">
102
- <div class="count">found in <%= @keys.files[key].count %> files</div>
103
- <div class="filelist">
104
- <div><%= @keys.files[key].join("</div><div>").html_safe %></div>
76
+ <span class="key">
77
+ <%= h tr.key %>
78
+ <% if tr.persisted %>
79
+ (saved)
80
+ <% else %>
81
+ (unsaved)
82
+ <% end %>
83
+ </span>
84
+ <a href="#" class="delete" title="Delete this key from database">X</a>
85
+ </div>
86
+ <% if tr.lines > 1 %>
87
+ <div class="long-translation">
88
+ <div class="translation-text">
89
+ <pre id="<%= tr.id %>_original"><%= tr.from_text %></pre>
90
+ <div class="clear"></div>
91
+ </div>
92
+ <div class="translation-textarea">
93
+ <%= text_area_tag("key[#{tr.key}]", tr.to_text, :rows => tr.lines, :id => tr.id) %>
94
+ <div class="clear"></div>
105
95
  </div>
96
+ <div class="clear"></div>
97
+ </div>
98
+ <% else %>
99
+ <div class="translation-text">
100
+ <code class="keytext" id="<%= tr.id %>_original"><%= tr.from_text %></code>
106
101
  </div>
102
+ <a class="change multiline" href="#" title="click to transform in a multi-line translation">&#9654;</a>
103
+ <%= text_field_tag("key[#{tr.key}]", tr.to_text, :size => tr.lines, :id => tr.id) %>
107
104
  <% end %>
108
- <span class="key"><%=h key %></span>
109
- <a href="#" class="delete" title="Delete this key from database">X</a>
110
- </div>
111
- <div class="translation-text">
112
- <code class="keytext" id="<%= tid %>_original"><%= from_text %></code>
113
- </div>
114
- <a class="change multiline" href="#" title="click to transform in a multi-line translation">&#9654;</a>
115
- <%= text_field_tag(field_name, to_text, :size => line_size, :id => tid) %>
116
- <% end %>
117
- </p>
118
- <p>
119
- </p>
120
- </div>
121
- <% end %>
122
- <p class="translate">
123
- Translations from <%= @from_locale %> to <%= @to_locale %>
124
- <%= submit_tag "Save Translations", style: 'float:right' %>
125
- </p>
126
- </div>
127
- <% end %>
105
+ </p>
106
+ </div>
107
+ <% end %>
108
+ <p class="translate">
109
+ Translations from <b><%= @from_locale %></b> to <b><%= @to_locale %></b>
110
+ <%= submit_tag "Save Translations", style: 'float:right' %>
111
+ </p>
112
+ </div>
113
+ <% end %>
128
114
  <% end %>
129
115
 
130
116
  <div class="paging clear">
131
- <%= render :partial => 'pagination', :locals => {:total_entries => @keys.all_keys.size, :per_page => @per_page} %>
117
+ <%= render :partial => 'pagination', :locals => { :total_entries => @total_entries, :per_page => @per_page } %>
132
118
  </div>
133
119
 
134
- </div>
120
+ </div>