i18n_viz 0.0.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/README.md +106 -15
  2. data/Rakefile +20 -0
  3. data/app/assets/javascripts/i18n_viz/gui.js.coffee +56 -0
  4. data/app/assets/javascripts/i18n_viz/processing.js.coffee +32 -0
  5. data/app/assets/javascripts/i18n_viz/settings.js.coffee.erb +5 -0
  6. data/app/assets/javascripts/i18n_viz/utils.js.coffee +8 -0
  7. data/app/assets/javascripts/i18n_viz.js +4 -82
  8. data/app/assets/stylesheets/i18n_viz.css +3 -3
  9. data/app/assets/stylesheets/{i18n_viz.sass → i18n_viz.css.sass} +1 -1
  10. data/lib/generators/i18n_viz/install_generator.rb +1 -1
  11. data/lib/i18n_viz/version.rb +3 -0
  12. data/lib/i18n_viz/view_helpers.rb +1 -1
  13. data/lib/i18n_viz.rb +2 -2
  14. data/test/dummy/README.rdoc +261 -0
  15. data/test/dummy/app/assets/javascripts/application.js.erb +16 -0
  16. data/test/dummy/app/assets/stylesheets/application.css.erb +14 -0
  17. data/test/dummy/app/controllers/test_controller.rb +4 -0
  18. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +1 -1
  20. data/test/dummy/app/views/test/test.html.erb +2 -0
  21. data/test/dummy/config/application.rb +26 -1
  22. data/test/dummy/config/environments/development.rb +12 -2
  23. data/test/dummy/config/environments/production.rb +19 -3
  24. data/test/dummy/config/environments/test.rb +5 -7
  25. data/test/dummy/config/initializers/i18n_viz.rb +5 -0
  26. data/test/dummy/config/initializers/inflections.rb +5 -0
  27. data/test/dummy/config/initializers/secret_token.rb +1 -1
  28. data/test/dummy/config/initializers/wrap_parameters.rb +5 -3
  29. data/test/dummy/config/locales/en.yml +1 -0
  30. data/test/dummy/config/routes.rb +1 -56
  31. data/test/dummy/log/development.log +6490 -0
  32. data/test/dummy/log/production.log +676 -0
  33. data/test/dummy/log/test.log +5464 -0
  34. data/test/dummy/public/500.html +0 -1
  35. data/test/dummy/tmp/cache/assets/CA3/C70/sprockets%2Fb0861b6c1fa62f655934129e40072c3a +0 -0
  36. data/test/dummy/tmp/cache/assets/CAA/2F0/sprockets%2F11421d959d2829cde7f44200d63b436b +0 -0
  37. data/test/dummy/tmp/cache/assets/CBA/CB0/sprockets%2F1794af7fbc3984f60b5335cf60840573 +0 -0
  38. data/test/dummy/tmp/cache/assets/CDD/640/sprockets%2F7dbb69499115ae2b043de298a03264b7 +0 -0
  39. data/test/dummy/tmp/cache/assets/CDF/CE0/sprockets%2F5b28ba105943c3d7648e1c3a64497d6a +0 -0
  40. data/test/dummy/tmp/cache/assets/D04/6D0/sprockets%2F2792527ad49637274a05a22bebccca27 +0 -0
  41. data/test/dummy/tmp/cache/assets/D14/750/sprockets%2Fa42ef296b90d25d74e048b312c7ff377 +0 -0
  42. data/test/dummy/tmp/cache/assets/D40/6C0/sprockets%2Fb3594c1e07aaf967887206dc5a1e23dd +0 -0
  43. data/test/dummy/tmp/cache/assets/D4D/730/sprockets%2F13fdf81363d2974af512288b8be95bff +0 -0
  44. data/test/dummy/tmp/cache/assets/D4E/BB0/sprockets%2F2e3b59f7005582b147ef8769bbfe44cf +0 -0
  45. data/test/dummy/tmp/cache/assets/D59/990/sprockets%2Fb749b65c4be001644b0e11af5ae57d1a +0 -0
  46. data/test/dummy/tmp/cache/assets/D65/C70/sprockets%2Fdaffaa499747888455a88d764cdd467f +0 -0
  47. data/test/dummy/tmp/cache/assets/D69/F70/sprockets%2Fc65d0f4dc24dd9e86c5c234b9d10b154 +0 -0
  48. data/test/dummy/tmp/cache/assets/D6C/DC0/sprockets%2F32d69b64b7ccdcb24f7235b5cd5247e2 +0 -0
  49. data/test/dummy/tmp/cache/assets/D71/FD0/sprockets%2F814ae60ca18d2f4d9403c672d9fe2de6 +0 -0
  50. data/test/dummy/tmp/cache/assets/D72/290/sprockets%2F7cd08947b83fdbb73ead2613c7f0930e +0 -0
  51. data/test/dummy/tmp/cache/assets/D7C/FF0/sprockets%2F813778cca328c7d9a71e6ad9bd6b5b93 +0 -0
  52. data/test/dummy/tmp/cache/assets/DA9/9C0/sprockets%2Fde7818edd5229ecc4f5808d25aea085d +0 -0
  53. data/test/dummy/tmp/cache/assets/DB7/FA0/sprockets%2F4db6264216dbe021be2b5de03d5defb2 +0 -0
  54. data/test/dummy/tmp/cache/assets/DE0/290/sprockets%2Fd8af96e9ce8323d61dfb2a0f2d8798ae +0 -0
  55. data/test/dummy/tmp/cache/assets/DFC/D80/sprockets%2F5ed6211e15876facc9cf6ea6bb0f25cc +0 -0
  56. data/test/dummy/tmp/cache/assets/EBC/970/sprockets%2Fb33decf60fdc18cbde88f1f58b0cfbcb +0 -0
  57. data/test/dummy/tmp/capybara/capybara-201203082358054799624742.html +14 -0
  58. data/test/dummy/tmp/capybara/capybara-20120308235915106889619.html +14 -0
  59. data/test/dummy/tmp/capybara/capybara-201203090025222771352245.html +14 -0
  60. data/test/dummy/tmp/capybara/capybara-201203090028349770270749.html +14 -0
  61. data/test/dummy/tmp/capybara/capybara-201203090028389443817250.html +14 -0
  62. data/test/dummy/tmp/capybara/capybara-201203090029025961464735.html +14 -0
  63. data/test/dummy/tmp/capybara/capybara-201203090039508941302493.html +13 -0
  64. data/test/dummy/tmp/capybara/capybara-201203090041003185277093.html +13 -0
  65. data/test/dummy/tmp/capybara/capybara-20120309004435508327178.html +13 -0
  66. data/test/dummy/tmp/capybara/capybara-201203090045138446441036.html +13 -0
  67. data/test/dummy/tmp/capybara/capybara-201203090048193302717265.html +13 -0
  68. data/test/dummy/tmp/capybara/capybara-201203090049161004423647.html +13 -0
  69. data/test/dummy/tmp/capybara/capybara-201203122230192174182390.html +15 -0
  70. data/test/dummy/tmp/capybara/capybara-201203122230459072559252.html +15 -0
  71. data/test/dummy/tmp/capybara/capybara-201203122234213756506718.html +15 -0
  72. data/test/dummy/tmp/capybara/capybara-201203122236587698907366.html +15 -0
  73. data/test/dummy/tmp/capybara/capybara-201203122240026617546436.html +15 -0
  74. data/test/dummy/tmp/capybara/capybara-201203122242011239858006.html +15 -0
  75. data/test/dummy/tmp/capybara/capybara-20120312224225934274263.html +15 -0
  76. data/test/dummy/tmp/capybara/capybara-201203122243455866509267.html +15 -0
  77. data/test/dummy/tmp/capybara/capybara-201203122244525753719355.html +15 -0
  78. data/test/dummy/tmp/capybara/capybara-201203122247524948625343.html +15 -0
  79. data/test/dummy/tmp/capybara/capybara-201203122251499219964247.html +15 -0
  80. data/test/dummy/tmp/capybara/capybara-20120312225811101957635.html +15 -0
  81. data/test/dummy/tmp/capybara/capybara-20120419151712430842680.html +17 -0
  82. data/test/dummy/tmp/capybara/capybara-201204201717339734853180.html +16 -0
  83. data/test/dummy/tmp/capybara/capybara-201204201726252553970846.html +16 -0
  84. data/test/dummy/tmp/capybara/capybara-201204201729292315980652.html +16 -0
  85. data/test/dummy/tmp/capybara/capybara-2012042018470684871227.html +16 -0
  86. data/test/dummy/tmp/capybara/capybara-201204201847593399926081.html +16 -0
  87. data/test/dummy/tmp/capybara/capybara-201204201849039479725100.html +16 -0
  88. data/test/dummy/tmp/capybara/capybara-201204211910105489043695.html +9655 -0
  89. data/test/dummy/tmp/capybara/capybara-201204211911405969387347.html +9655 -0
  90. data/test/dummy/tmp/capybara/capybara-201204211914247245458395.html +9655 -0
  91. data/test/dummy/tmp/capybara/capybara-201204211914559132678948.html +1 -0
  92. data/test/dummy/tmp/capybara/capybara-201204211915253938423144.html +9771 -0
  93. data/test/dummy/tmp/capybara/capybara-201204211915525043905375.html +9771 -0
  94. data/test/dummy/tmp/capybara/capybara-201204211916473893479062.html +9770 -0
  95. data/test/dummy/tmp/capybara/capybara-201204211917051111503402.html +9770 -0
  96. data/test/dummy/tmp/capybara/capybara-201204211917468910258726.html +9770 -0
  97. data/test/dummy/tmp/capybara/capybara-201204211923518328716227.html +9654 -0
  98. data/test/dummy/tmp/capybara/capybara-201204211924283065722810.html +9771 -0
  99. data/test/dummy/tmp/capybara/capybara-20120421192447964476108.html +9770 -0
  100. data/test/dummy/tmp/capybara/capybara-201204211925044795848945.html +9771 -0
  101. data/test/dummy/tmp/capybara/capybara-20120421192704738894917.html +9655 -0
  102. data/test/dummy/tmp/capybara/capybara-201204211927362604064807.html +9771 -0
  103. data/test/dummy/tmp/capybara/capybara-201204211927588279644614.html +9771 -0
  104. data/test/dummy/tmp/capybara/capybara-201205072257302163142470.html +16 -0
  105. data/test/dummy/tmp/capybara/capybara-201205072258275803776347.html +16 -0
  106. data/test/dummy/tmp/capybara/capybara-201205072259123253975262.html +16 -0
  107. data/test/dummy/tmp/capybara/capybara-201205072300473974343273.html +16 -0
  108. data/test/dummy/tmp/capybara/capybara-201205072301121512038123.html +21 -0
  109. data/test/dummy/tmp/capybara/capybara-201205072302159723462465.html +21 -0
  110. data/test/dummy/tmp/capybara/capybara-201205072302329392138562.html +21 -0
  111. data/test/dummy/tmp/capybara/capybara-201205072303208896190157.html +22 -0
  112. data/test/dummy/tmp/capybara/capybara-201205072303403954362976.html +22 -0
  113. data/test/dummy/tmp/capybara/capybara-201205072303595349712847.html +22 -0
  114. data/test/i18n_viz_test.rb +48 -3
  115. data/test/test_helper.rb +20 -0
  116. metadata +197 -16
  117. data/lib/tasks/i18n_viz_tasks.rake +0 -4
  118. data/test/dummy/app/assets/javascripts/application.js +0 -9
  119. data/test/dummy/app/assets/stylesheets/application.css +0 -7
  120. data/test/dummy/config/database.yml +0 -25
  121. /data/lib/i18n_viz/{rails.rb → engine.rb} +0 -0
data/README.md CHANGED
@@ -1,44 +1,94 @@
1
1
  # I18nViz
2
2
 
3
- Gem to visualize i18n strings within a rails project.
3
+ [![Build Status](https://secure.travis-ci.org/jhilden/i18n_viz.png?branch=master)](http://travis-ci.org/jhilden/i18n_viz)
4
+
5
+ Gem to visualize i18n strings within a rails/ruby project.
6
+
7
+ **Problem**:
8
+
9
+ It is ver difficult for non-developers (e.g. translators and product managers) working with i18n Rails apps to make the connection from a string within the app to the correct i18n key to edit the corresponding translation. "I would like to tweak the wording of the subtitle on this page, what string do I need to edit?"
10
+
11
+ **Solution**:
12
+
13
+ My solution is to hack the i18n keys into the frontend, so that the keys can be displayed as nice overlay tooltips on top of their strings right within the app.
14
+
15
+ If you you use a translation management app, such as http://webtranslateit.com, you get the additional benefit of clickable links that point you right to the correct string to edit within the translation tool.
16
+
17
+ More features (like inline editing) are possible in the future.
18
+
4
19
 
5
- More description coming soon ...
6
20
 
7
21
  ## Requirements
8
22
 
9
- i18n_viz.js currentyl depends on jQuery being alread loaded in your app. Tested with jQuery 1.6.1
23
+ i18n_viz.js currently depends on jQuery being already loaded in your app (Tested with jQuery 1.6.1, but should also work with other versions)
24
+
25
+ In a Rails 3.1+ application you should simply include `gem 'jquery-rails'` in your Gemfile and your asset pipeline manifest.
26
+
10
27
 
11
28
  ## Installation
12
29
 
13
30
  ##### 1. Install the gem
14
31
 
15
- Add the following line to your Gemfile
32
+ Add the `i18n_viz` to your Gemfile
16
33
 
17
- gem 'i18n_viz', :git =>'git://github.com/jhilden/i18n_viz.git'
34
+ gem 'i18n_viz'
18
35
 
19
36
  And run
20
37
 
21
38
  bundle install
22
39
 
23
40
 
24
- ##### 2. Run install generator
41
+ ##### 2. Include the assets
42
+
43
+ I18nVIz is build as a Rails::Engine, which allows it provide its assets directly to the Rails asset pipeline for inclusion in your app. Therefore, if you have a Rails 3.1+ app and are using the asset pipeline, you can include the I18nViz assets very easily:
44
+
45
+ Either you add the following line to your asset pipeline manifest file (`app/assets/javascripts/application.js`):
25
46
 
26
- rails generate i18n_viz:install
47
+ // = require i18n_viz
27
48
 
28
- This will copy the required assets (i18n_viz.js, i18n_viz.css) to your public directory and create a new initializer in your rails app.
49
+ Or, you turn your manifest file into an `.erb` template (`app/assets/javascripts/application.js.erb`) and this code:
29
50
 
51
+ <% require_asset("i18n_viz") if I18nViz.enabled? %>
30
52
 
31
- ##### 3. Include assets
53
+ This ensures that the asset will only be included if the I18nViz gem is enabled and makes most sense in combination with an initializer (see below) that enables the gem based on the enviornment.
54
+
55
+ !Gotcha: You need to leave a blank line between your asset pipeline directives (`require`, `require_tree`, ...) and the erb line above, otherwise it will NOT work!
56
+
57
+ For the stylesheet is is very similar, either you you add a simple directive in your manifest (`app/assets/stylesheets/application.js`):
58
+
59
+ /* = require i18n_viz.css */
60
+
61
+ Or you turn it into an `erb` template (`app/assets/stylesheets/application.css.erb`) and add this at the top of the file:
62
+
63
+ <% require_asset "i18n_viz" if I18nViz.enabled? %>
64
+
65
+ <!--Or if you are using SASS, something like:
66
+
67
+ @import "i18n_viz"-->
68
+
69
+
70
+ If you are not using Rails 3.1+ and the asset pipeline you will need to compile the Coffeescript to Javascript and copy and include the assets in the right places. If there should be demand for it I might provide some more comfortable way of doing this.
32
71
 
33
- For example like this in your app's layout:
34
72
 
35
- - if display_i18n_viz?
36
- = stylesheet_link_tag("i18n_viz")
37
- = javascript_tag "var i18n_viz_key_url = '#{I18nViz.key_url}';"
38
- = javascript_include_tag "i18n_viz"
73
+ #### 3. Create initializer (optional)
39
74
 
75
+ In order to provide some custom setting for the I18nViz gem, it might make sense to create and initializer.
76
+
77
+ E.g. `config/initializers/i18n_viz.rb`:
78
+
79
+ # encoding: utf-8
80
+ unless defined?(I18nViz).nil?
81
+ # determine under which condition the gem should be active
82
+ I18nViz.enabled = !Rails.env.production?
83
+
84
+ # Link to display in the I18nViz tooltip
85
+ # e.g. pointing to that particular string in your apps translation tool
86
+ # the i18n key will be appended to that URL
87
+ I18nViz.external_tool_url = "https://webtranslateit.com/en/projects/1234567/locales/en..de/strings?utf8=✓&s="
88
+ end
40
89
 
41
- ## How it works
90
+
91
+ # How it works
42
92
 
43
93
  The gem works by overwriting the t() and translate() helpers in your rails app to add the key of the i18n string after the actual translated content:
44
94
 
@@ -59,6 +109,47 @@ The i18n_viz Javascript then parses this and enriches it into:
59
109
 
60
110
  The so enriched elements then get nice little tooltips attached with the i18n keys and possibly links to where they can be found/changed.
61
111
 
112
+
113
+ ## Gotchas & Limitations
114
+
115
+ #### Works only in the view layer
116
+
117
+ The keys will currently only work for strings that are translated in the view layer using the `translate()` and `t()` i18n view helpers. If you translate a string the model layer using `I18n.translate` method directly (e.g. ActiveRecord validations) the keys are not displayed in the frontend.
118
+
119
+
120
+ #### Assigning I18n output to variables
121
+
122
+ If you should be assigning i18n output directly into variables (e.g. within inline javascript, JS data-attributes, or other variables), the whole `--key--` thing might actually break your application.
123
+
124
+ For example this usage of a data-attribute:
125
+
126
+ de:
127
+ date:
128
+ js_format: "dd.mm.yyyy"
129
+
130
+
131
+ %body{:"data-date-format" => t("date.js_format")}
132
+
133
+ Will result in this broken output:
134
+
135
+ <body data-date-format="dd.mm.yyyy--date.js_format--">
136
+
137
+ In those cases you need to pass an additional parameter `:i18n_viz => false` to the translate method in order to not append the key.
138
+
139
+ Example:
140
+
141
+ %body{:"data-date-format" => t("date.js_format", :i18n_viz => false)}
142
+
143
+ -----
144
+
145
+ <body data-date-format="dd.mm.yyyy">
146
+
147
+
148
+ # Thanks
149
+
150
+ Big thanks to my employer [Railslove](http://railslove.com) for supporting my open source work and to everybody who helped me.
151
+
152
+
62
153
  ### License
63
154
 
64
155
  This project is under MIT-LICENSE.
data/Rakefile CHANGED
@@ -20,18 +20,38 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
23
25
 
24
26
 
25
27
  Bundler::GemHelper.install_tasks
26
28
 
27
29
  require 'rake/testtask'
28
30
 
31
+ task :js_tests do
32
+ system("cd test/dummy")
33
+ system("RAILS_ENV=test rake assets:precompile")
34
+ system("cd ../..")
35
+ system("evergreen run")
36
+ system("cd test/dummy")
37
+ system("RAILS_ENV=test rake assets:clean")
38
+ end
39
+
29
40
  Rake::TestTask.new(:test) do |t|
30
41
  t.libs << 'lib'
31
42
  t.libs << 'test'
32
43
  t.pattern = 'test/**/*_test.rb'
33
44
  t.verbose = false
45
+
46
+ #Rake::Task[:js_tests].invoke
34
47
  end
35
48
 
49
+ task :travis do
50
+ ["rake test"].each do |cmd|
51
+ puts "Starting to run #{cmd}..."
52
+ system("export DISPLAY=:99.0 && bundle exec #{cmd}")
53
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
54
+ end
55
+ end
36
56
 
37
57
  task :default => :test
@@ -0,0 +1,56 @@
1
+ $(document).ready () ->
2
+ # append i18n tooltip
3
+ $("body")
4
+ .append('<div id="i18n_viz_tooltip">...</div>')
5
+ .click () -> $("#i18n_viz_tooltip").hide()
6
+
7
+ # enrich elements with i18n attributes, classes, tooltip events
8
+ $.fn.initGUI = (keys) ->
9
+ $(this)
10
+ # tooltip events
11
+ .mouseenter () ->
12
+ $tooltip = $("#i18n_viz_tooltip")
13
+
14
+ top = $(this).offset().top - $tooltip.outerHeight()
15
+ left = $(this).offset().left
16
+ if (top < 0)
17
+ top = $(this).offset().top + $(this).height() + 10
18
+
19
+ $tooltip.html('');
20
+ keys.forEach (value) ->
21
+ if (window.I18nViz.external_tool_url.length > 0)
22
+ $tooltip.append('<a href="' + window.I18nViz.external_tool_url + value + '" target="_blank">' + value + '</a>')
23
+ else
24
+ $tooltip.append("<span>"+value+"</span>")
25
+
26
+ $tooltip
27
+ .css({top: top, left: left})
28
+ .show()
29
+ $(this)
30
+
31
+ # process elements with i18n strings in their text
32
+ $(":i18n-textnode").each () ->
33
+ $i18n_textnode = $(this)
34
+ i18n_keys = window.I18nViz.extractI18nKeysFromText($i18n_textnode.text())
35
+
36
+ $i18n_textnode
37
+ .enrichWithI18nData(i18n_keys)
38
+ .initGUI(i18n_keys)
39
+ .clearI18nText()
40
+
41
+ # process elements with i18n strings in the value or placeholder attributes
42
+ $("input:i18n-value-placeholder").each () ->
43
+ $i18n_input_element = $(this)
44
+ input_value = $i18n_input_element.val()
45
+ placeholder_value = $i18n_input_element.attr('placeholder')
46
+
47
+ i18n_keys = extractI18nKeysFromText(input_value + placeholder_value)
48
+
49
+ $i18n_input_element.enrichWithI18nData(i18n_keys)
50
+
51
+ # clear i18n data from value and placeholder attributes
52
+ cleared_input_value = input_value.replace(window.I18nViz.global_regex, "")
53
+ $(this).val( cleared_input_value )
54
+ if (placeholder_value)
55
+ cleared_placeholder_value = placeholder_value.replace(window.I18nViz.global_regex, "")
56
+ $(this).attr('placeholder', cleared_placeholder_value)
@@ -0,0 +1,32 @@
1
+ # enrich elements with i18n attributes, classes
2
+ $.fn.enrichWithI18nData = () ->
3
+ i18n_keys = I18nViz.extractI18nKeysFromText $(this).text()
4
+ if i18n_keys != null
5
+ $(this)
6
+ .addClass("i18n-viz")
7
+ .data("i18n-keys", i18n_keys)
8
+ $(this)
9
+
10
+ # clear i18n data from element text
11
+ $.fn.clearI18nText = () ->
12
+ $(this).textNodes().each () ->
13
+ $(this).replaceWith $(this).text().replace(I18nViz.global_regex, "")
14
+ $(this)
15
+
16
+ # extract i18n keys from a textnode (e.g. "translated text--en.translation.key--")
17
+ I18nViz.extractI18nKeysFromText = (text) ->
18
+ keys = text.match(I18nViz.global_regex)
19
+ if keys
20
+ keys.forEach (value, index) -> keys[index] = value.replace(/--/g, "")
21
+ keys
22
+ else
23
+ null
24
+
25
+ # custom :i18n selectors
26
+ $.extend $.expr[':'], {
27
+ 'i18n-textnode': (el) ->
28
+ I18nViz.regex.test $(el).textNodes().text()
29
+ ,
30
+ 'i18n-value-placeholder': (el) ->
31
+ (I18nViz.regex.test($(el).val()) || I18nViz.regex.test($(el).attr('placeholder')))
32
+ }
@@ -0,0 +1,5 @@
1
+ window.I18nViz = {
2
+ regex: new RegExp(/--([a-z0-9_\.]+)--/i),
3
+ global_regex: new RegExp(/--([a-z0-9_\.]+)--/gi),
4
+ external_tool_url: '<%= I18nViz.external_tool_url %>'
5
+ }
@@ -0,0 +1,8 @@
1
+ # get all the textnode children for an element
2
+ # edited
3
+ $.fn.textNodes = () ->
4
+ $(this).contents().filter () ->
5
+ try
6
+ (this.nodeType == 3)
7
+ catch err
8
+ false
@@ -1,82 +1,4 @@
1
- $(document).ready(function(){
2
- var i18n_regexp = new RegExp(/--([a-z0-9_\.]+)--/i);
3
- var i18n_regexp_global = new RegExp(/--([a-z0-9_\.]+)--/gi);
4
-
5
- // i18n tooltip
6
- $("body")
7
- .append('<div id="i18n-viz-tooltip">...</div>')
8
- .click(function() { $("#i18n-viz-tooltip").hide() })
9
-
10
- $.fn.textNodes = function() {
11
- return $(this).contents().filter(function(){ return this.nodeType == 3 });
12
- };
13
-
14
- // add i18n attributes, classes, events
15
- $.fn.addI18n = function(keys) {
16
- $(this)
17
- .addClass("i18n-viz")
18
- .data("i18n-keys", keys)
19
-
20
- .mouseenter(function(){
21
- $tooltip = $("#i18n-viz-tooltip");
22
-
23
- var top = $(this).offset().top - 40;
24
- var left = $(this).offset().left;
25
- if (top < 0) top = $(this).offset().top + $(this).height() + 10;
26
-
27
- $tooltip.html('');
28
- keys.forEach(function(value) {
29
- if (i18n_viz_key_url) {
30
- $tooltip.append('<a href="'+i18n_viz_key_url+value+'" target="_blank">'+value+'</a>')
31
- } else {
32
- $tooltip.append("<span>"+value+"</span>")
33
- }
34
- });
35
-
36
- $tooltip
37
- .css({top: top, left: left})
38
- .show()
39
- })
40
- .mouseleave(function() {
41
- setTimeout(function() { $("#i18n-viz-tooltip").fadeOut('fast'); }, 1500);
42
- });
43
- };
44
-
45
- function getI18nKeys(text) {
46
- var keys = text.match(i18n_regexp_global);
47
- keys.forEach(function(value, index) { keys[index] = value.replace(/--/g, "") });
48
- return keys;
49
- }
50
-
51
- // build custom :i18n selectors
52
- $.extend($.expr[':'], {
53
- 'i18n-el': function (el) {
54
- return i18n_regexp.test( $(el).textNodes().text() );
55
- },
56
- 'i18n-value': function (el) {
57
- return (i18n_regexp.test($(el).val()) || i18n_regexp.test($(el).attr('placeholder')))
58
- }
59
- });
60
-
61
- $(":i18n-el").each(function(){
62
- var text = $(this).text();
63
-
64
- var keys = getI18nKeys(text);
65
- $(this).addI18n(keys);
66
-
67
- $(this).textNodes().each(function() { $(this).replaceWith( $(this).text().replace(i18n_regexp_global, "") ); })
68
- });
69
-
70
- $("input:i18n-value").each(function(){
71
- var value = $(this).val();
72
- var placeholder = $(this).attr('placeholder');
73
- var text = value + placeholder;
74
-
75
- var keys = getI18nKeys(text);
76
- $(this).addI18n(keys);
77
-
78
- $(this).val(value.replace(i18n_regexp_global, ""));
79
- if (placeholder) $(this).attr('placeholder', placeholder.replace(i18n_regexp_global, ""));
80
- });
81
- })
82
-
1
+ //= require i18n_viz/settings
2
+ //= require i18n_viz/utils
3
+ //= require i18n_viz/processing
4
+ //= require i18n_viz/gui
@@ -1,5 +1,5 @@
1
1
  /* line 4, ../../../app/stylesheets/i18n-viz.sass */
2
- #i18n-viz-tooltip {
2
+ #i18n_viz_tooltip {
3
3
  display: none;
4
4
  position: absolute;
5
5
  top: 100px;
@@ -21,11 +21,11 @@
21
21
  padding: 10px;
22
22
  }
23
23
  /* line 14, ../../../app/stylesheets/i18n-viz.sass */
24
- #i18n-viz-tooltip a, #i18n-viz-tooltip span {
24
+ #i18n_viz_tooltip a, #i18n_viz_tooltip span {
25
25
  margin-right: 10px;
26
26
  }
27
27
  /* line 16, ../../../app/stylesheets/i18n-viz.sass */
28
- #i18n-viz-tooltip a:last-child, #i18n-viz-tooltip span:last-child {
28
+ #i18n_viz_tooltip a:last-child, #i18n_viz_tooltip span:last-child {
29
29
  margin-right: 0;
30
30
  }
31
31
 
@@ -1,7 +1,7 @@
1
1
  @import "compass/css3/border-radius"
2
2
  @import "compass/css3/gradient"
3
3
 
4
- #i18n-viz-tooltip
4
+ #i18n_viz_tooltip
5
5
  display: none
6
6
  position: absolute
7
7
  top: 100px
@@ -11,7 +11,7 @@ module I18nViz
11
11
  def create_initializer
12
12
  initializer "i18n_viz.rb", %Q{
13
13
  I18nViz.enabled = !Rails.env.production?
14
- I18nViz.key_url = "" # link to more information about each i18n key, e.g. "http://mytranslationtool.com/?key=" -- the key (e.g. 'en.foo.bar') will be appended to this URL
14
+ I18nViz.external_tool_url = "" # link to more information about each i18n key, e.g. "http://mytranslationtool.com/?key=" -- the key (e.g. 'en.foo.bar') will be appended to this URL
15
15
  }
16
16
  end
17
17
  end
@@ -0,0 +1,3 @@
1
+ module I18nViz
2
+ VERSION = "0.3.0"
3
+ end
@@ -3,6 +3,7 @@ module I18nViz
3
3
 
4
4
  def translate(key, options = {}) # TODO: alias
5
5
  if display_i18n_viz? && options[:i18n_viz] != false
6
+ # TODO: ActionController::Base.perform_caching = false if ActionController::Base.perform_caching == true
6
7
  "#{super(key, options)}--#{key}--"
7
8
  else
8
9
  super(key, options)
@@ -14,7 +15,6 @@ module I18nViz
14
15
  return unless display_i18n_viz?
15
16
 
16
17
  stylesheet_link_tag("i18n_viz")
17
- javascript_tag "var i18n_viz_key_url = '#{I18nViz.key_url}';"
18
18
  javascript_include_tag "i18n_viz"
19
19
  end
20
20
 
data/lib/i18n_viz.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module I18nViz
2
- mattr_accessor :key_url, :enabled
2
+ mattr_accessor :external_tool_url, :enabled
3
3
 
4
4
  @@enabled = true
5
5
 
@@ -9,5 +9,5 @@ module I18nViz
9
9
  end
10
10
 
11
11
  require 'i18n_viz/view_helpers'
12
- require 'i18n_viz/rails'
12
+ require 'i18n_viz/engine'
13
13