rosetta 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d2574c83847a071d1d3e32de114d2bd61120955
4
+ data.tar.gz: de47cfb942fb0a6e44142a52498f4ffe72e0b2de
5
+ SHA512:
6
+ metadata.gz: c41bec5e754a3723c5b21c52fe75aa1d0e4e8a25335ec2a57d4f9948e87dcd099885136b50d17dedd34f82870bd7b07571f1815d1b7f62c28996fecf44fe2a7a
7
+ data.tar.gz: 24f6bc132e4e933515c300ef10589ec90362e7be296372a2fcbc691c24be2c9a59231416051773638d624c0ecf182a8069eda0ca71ffc4ce17b65e6a0c8f13b1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 MarsBased
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Rosetta
2
+
3
+ [![Build Status](https://travis-ci.org/MarsBased/rosetta.svg?branch=master)](https://travis-ci.org/MarsBased/rosetta)
4
+
5
+ Rosetta is a library for Rails that helps you identify the translations that are being used on your app pages. The library adds an expandable menu to each page that shows all phrases being used in the page along with additional info depending on the [Repository](#repositories) used.
6
+
7
+ It is especially useful if you use the [OneSky translation service](https://www.oneskyapp.com/) since it gives you direct links to edit the translations on OneSky. This makes it easy for copy writers of your app to see the texts in context and edit the translations.
8
+
9
+ When using regular translations, it shows the file where translation is so you can more easily find and edit it.
10
+
11
+ ![Screenshot](screenshot.png)
12
+
13
+ ## Dependencies
14
+
15
+ Rosetta requires a Ruby version >= 2.3
16
+
17
+ ## Repositories
18
+
19
+ The phrases menu is different depending on the way you manage your translations. There are currently 2 repositories: Local (default) and OneSky
20
+
21
+ ### Local Repository
22
+
23
+ This is the default repository and shows translations managed manually via YML files. It shows the file where each translation is stored to be able to easily find it.
24
+
25
+ It requires no further configuration.
26
+
27
+ ### OneSky repository
28
+
29
+ Use this repository if you manage your translations using the [OneSky translation service](https://www.oneskyapp.com/). It adds a link to each translations pointing to the edit page for that text in OneSky.
30
+
31
+ It requires 2 configuration options:
32
+ * subdomain
33
+ * project_id
34
+
35
+ ## Installation
36
+ Add this to your Gemfile:
37
+
38
+ ```ruby
39
+ gem 'rosetta', '~> 1.0'
40
+ ```
41
+
42
+ and run the `bundle install` command.
43
+
44
+ To generate the initializer file run `rails g rosetta:install`
45
+
46
+ ## Getting Started
47
+
48
+ ### 1. Enable the library
49
+
50
+ By default, Rosetta is disabled. You need to explicitly enable it when desired. Usually that will depend on the current user making the request.
51
+
52
+ To enable it in a per-request basis add a `before_action :enable_rosetta` to the desired controller and add an `if` condition if necessary. Example:
53
+
54
+ ```ruby
55
+ before_action :enable_rosetta, if: ->() { current_user.admin? }
56
+ ```
57
+
58
+ ### 2. Render the menu where desired
59
+
60
+ In order to show the menu with the translations you need to indicate where you want to render it. Usually this will be in your application's layout. Add this at the end of the body of your `layours/application.html.erb`:
61
+
62
+ ```ruby
63
+ <%= render rosetta_menu %>
64
+ ```
65
+
66
+ ## Configuration
67
+
68
+ You can configure the library through the initializer.
69
+
70
+ Example:
71
+ ```ruby
72
+ Rosetta.setup do |config|
73
+ # OneSky repository config
74
+ config.repository = Rosetta::Repositories::Onesky.new
75
+ config.repository.project_id = ENV['ONESKY_PROJECT_ID']
76
+ config.repository.subdomain = ENV['ONESKY_SUBDOMAIN']
77
+
78
+ # Local repository config
79
+ config.repository = Rosetta::Repositories::Local
80
+ end
81
+ ```
82
+
83
+ ## Development
84
+
85
+ When first developing, you need to run `bundle install`.
86
+
87
+ Run the specs with `rspec spec`.
88
+
89
+ Launch the dummy app with `rails s`.
90
+
91
+ ## Credits
92
+
93
+ ![marsbased](https://marsbased.com/assets/marsbased-readme.svg)
94
+
95
+ Rosetta is maintained and funded by [MarsBased][marsbased]
96
+
97
+ The names and logos for MarsBased are trademarks of MarsBased.
98
+
99
+ [marsbased]: http://marsbased.com
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ require 'bundler/gem_tasks'
11
+
12
+ task default: :rspec
File without changes
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
+ width="357px" height="357px" viewBox="0 0 357 357" style="enable-background:new 0 0 357 357;" xml:space="preserve">
6
+ <g>
7
+ <g id="close">
8
+ <polygon points="357,35.7 321.3,0 178.5,142.8 35.7,0 0,35.7 142.8,178.5 0,321.3 35.7,357 178.5,214.2 321.3,357 357,321.3
9
+ 214.2,178.5 "/>
10
+ </g>
11
+ </g>
12
+ <g>
13
+ </g>
14
+ <g>
15
+ </g>
16
+ <g>
17
+ </g>
18
+ <g>
19
+ </g>
20
+ <g>
21
+ </g>
22
+ <g>
23
+ </g>
24
+ <g>
25
+ </g>
26
+ <g>
27
+ </g>
28
+ <g>
29
+ </g>
30
+ <g>
31
+ </g>
32
+ <g>
33
+ </g>
34
+ <g>
35
+ </g>
36
+ <g>
37
+ </g>
38
+ <g>
39
+ </g>
40
+ <g>
41
+ </g>
42
+ </svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fille="#686866" d="M304 416H24c-13.255 0-24-10.745-24-24V120c0-13.255 10.745-24 24-24h280v320zm-120.676-72.622A12 12 0 0 0 194.839 352h22.863c8.22 0 14.007-8.078 11.362-15.861L171.61 167.085a12 12 0 0 0-11.362-8.139h-32.489a12.001 12.001 0 0 0-11.362 8.139L58.942 336.139C56.297 343.922 62.084 352 70.304 352h22.805a12 12 0 0 0 11.535-8.693l9.118-31.807h60.211l9.351 31.878zm-39.051-140.42s4.32 21.061 7.83 33.21l10.8 37.531h-38.07l11.07-37.531c3.51-12.15 7.83-33.21 7.83-33.21h.54zM616 416H336V96h280c13.255 0 24 10.745 24 24v272c0 13.255-10.745 24-24 24zm-36-228h-64v-16c0-6.627-5.373-12-12-12h-16c-6.627 0-12 5.373-12 12v16h-64c-6.627 0-12 5.373-12 12v16c0 6.627 5.373 12 12 12h114.106c-6.263 14.299-16.518 28.972-30.023 43.206-6.56-6.898-12.397-13.91-17.365-20.933-3.639-5.144-10.585-6.675-15.995-3.446l-7.28 4.346-6.498 3.879c-5.956 3.556-7.693 11.421-3.735 17.117 6.065 8.729 13.098 17.336 20.984 25.726-8.122 6.226-16.841 12.244-26.103 17.964-5.521 3.41-7.381 10.556-4.162 16.19l7.941 13.896c3.362 5.883 10.935 7.826 16.706 4.276 12.732-7.831 24.571-16.175 35.443-24.891 10.917 8.761 22.766 17.102 35.396 24.881 5.774 3.556 13.353 1.618 16.717-4.27l7.944-13.903c3.213-5.623 1.37-12.76-4.135-16.171a312.737 312.737 0 0 1-26.06-18.019c21.024-22.425 35.768-46.289 42.713-69.85H580c6.627 0 12-5.373 12-12v-16c0-6.625-5.373-11.998-12-11.998z"/></svg>
@@ -0,0 +1,195 @@
1
+ <% if rosetta? %>
2
+ <style>
3
+ .phrases-menu {
4
+ height: 100%;
5
+ width: 350px;
6
+ position: fixed;
7
+ z-index: 1000;
8
+ top: 0;
9
+ font-family: Arial, Helvetica, sans-serif;
10
+ left: -350px;
11
+ background-color: #F5F5F5;
12
+ transition: 0.2s;
13
+ -webkit-box-shadow: 3px 4px 6px 0 rgba(0, 0, 0, 0.2);
14
+ box-shadow: 3px 4px 6px 0 rgba(0, 0, 0, 0.2);
15
+ }
16
+
17
+ .phrases-menu.open{
18
+ left: 0px;
19
+ }
20
+
21
+ .phrases-menu__header {
22
+ height: 45px;
23
+ position: relative;
24
+ }
25
+
26
+ .phrases-menu__content {
27
+ height: calc(100% - 46px);
28
+ padding: 2px 0 12px 0;
29
+ overflow: auto;
30
+ box-sizing: border-box;
31
+ }
32
+
33
+ .phrases-menu__title{
34
+ margin: 0;
35
+ padding: 12px 9px;
36
+ font-size: 18px;
37
+ text-transform: uppercase;
38
+ border-bottom: 1px solid #dedede;
39
+ }
40
+
41
+ .phrases-menu__block {
42
+ color: #000000;
43
+ display: block;
44
+ text-decoration: none;
45
+ padding: 10px 10px;
46
+ transition: 0.3s;
47
+ font-size: 12px;
48
+ margin: 10px 10px 0px 10px;
49
+ border-radius: 3px;
50
+ background: #ffffff;
51
+ border: 1px solid #dedede;
52
+ }
53
+
54
+ .phrases-menu:not(.local) .phrases-menu__block:hover {
55
+ color: #e81d08;
56
+ cursor: pointer;
57
+ border: 1px solid #e81d08;
58
+ text-decoration: none;
59
+ }
60
+
61
+ .phrases-menu__key{
62
+ font-size: 12px;
63
+ font-weight: 900;
64
+ margin-bottom: 11px;
65
+ }
66
+
67
+ .phrases-menu__phrase{
68
+ font-size: 13px;
69
+ margin-bottom: 11px;
70
+ }
71
+
72
+ .phrases-menu__phrase:last-child{
73
+ margin-bottom: 0;
74
+ }
75
+
76
+ .phrases-menu__path{
77
+ font-size: 12px;
78
+ color: #9a9a9a;
79
+ transition: 0.3s;
80
+ }
81
+
82
+ .phrases-menu:not(.local) .phrases-menu__block:hover .phrases-menu__path {
83
+ color: #e81d08;
84
+ }
85
+
86
+ .phrases-menu__footer {
87
+ text-align: center;
88
+ max-width: 75%;
89
+ margin: 25px auto 0;
90
+ }
91
+
92
+ .phrases-menu__footer h1 {
93
+ font-size: 18px;
94
+ color: #7b7b7b;
95
+ }
96
+
97
+ .phrases-menu__footer p {
98
+ font-size: 12px;
99
+ color: #9a9a9a;
100
+ line-height: 1.4;
101
+ }
102
+
103
+ .phrases-menu__footer a {
104
+ color: inherit;
105
+ }
106
+
107
+ .phrases-menu__footer a:hover {
108
+ color: #e81d08;
109
+ }
110
+
111
+ .open-phrases-menu-btn{
112
+ background-color: #F5F5F5;
113
+ color: #686866;
114
+ -webkit-box-shadow: 4px 3px 5px 0 rgba(0, 0, 0, 0.2);
115
+ box-shadow: 4px 3px 5px 0 rgba(0, 0, 0, 0.2);
116
+ display: block;
117
+ position: absolute;
118
+ right: -55px;
119
+ height: 45px;
120
+ width: 55px;
121
+ border-radius: 0 0 3px 0;
122
+ top: 0px;
123
+ cursor: pointer;
124
+ }
125
+
126
+ .phrases-menu__closebtn {
127
+ transition: 0.3s;
128
+ display: none;
129
+ }
130
+
131
+ .phrases-menu.open .phrases-menu__closebtn {
132
+ display: block;
133
+ }
134
+
135
+ .phrases-menu.open .phrases-menu__openbtn {
136
+ display: none;
137
+ }
138
+
139
+ .phrases-menu__closebtn img {
140
+ height: 20px;
141
+ position: absolute;
142
+ top: 50%;
143
+ left: 50%;
144
+ -webkit-transform: translate(-50%, -50%);
145
+ -ms-transform: translate(-50%, -50%);
146
+ transform: translate(-50%, -50%);
147
+ }
148
+
149
+ .phrases-menu__openbtn img {
150
+ height: 30px;
151
+ position: absolute;
152
+ top: 50%;
153
+ left: 50%;
154
+ -webkit-transform: translate(-50%, -50%);
155
+ -ms-transform: translate(-50%, -50%);
156
+ transform: translate(-50%, -50%);
157
+ }
158
+
159
+ </style>
160
+
161
+ <div id="phrasesMenu" class="phrases-menu <%= Rosetta.repository.id %>">
162
+ <div class="open-phrases-menu-btn" onclick="toggleNav()">
163
+ <div class="phrases-menu__openbtn">
164
+ <%= image_tag('rosetta/language_icon.svg') %>
165
+ </div>
166
+ <div class="phrases-menu__closebtn">
167
+ <%= image_tag('rosetta/close.svg') %>
168
+ </div>
169
+ </div>
170
+ <div class="phrases-menu__header">
171
+ <h1 class="phrases-menu__title">
172
+ <%= Rosetta.repository.label %> <b>[<%= Rosetta.locale %>]</b>
173
+ </h1>
174
+ </div>
175
+ <div class="phrases-menu__content">
176
+ <% Rosetta.phrases.each do |phrase| %>
177
+ <%= render "rosetta/#{Rosetta.repository.id}/actions",
178
+ phrase: phrase %>
179
+ <% end %>
180
+
181
+ <div class="phrases-menu__footer">
182
+ <h1>Rosetta</h1>
183
+ <p>Rosetta is available as open source under the terms of the <a href="http://opensource.org/licenses/MIT" target="_blank">MIT License</a>.</p>
184
+ <p><a href="https://github.com/MarsBased/rosetta" target="_blank">View in Github</a></p>
185
+ </div>
186
+ </div>
187
+ </div>
188
+
189
+ <script type="text/javascript">
190
+ /* Toggle the Translate menu */
191
+ function toggleNav() {
192
+ document.getElementById("phrasesMenu").classList.toggle("open");
193
+ }
194
+ </script>
195
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <div class="phrases-menu__block">
2
+ <div class="phrases-menu__key">
3
+ <%= phrase.code %>
4
+ </div>
5
+
6
+ <div class="phrases-menu__phrase">
7
+ <%= phrase.text %>
8
+ </div>
9
+
10
+ <div class="phrases-menu__path">
11
+ <%= phrase.repository_link %>
12
+ </div>
13
+ </div>
@@ -0,0 +1,11 @@
1
+ <%= link_to(phrase.repository_link, target: '_blank', class: 'phrases-menu__block') do %>
2
+ <div class="phrases-menu__actions">
3
+ <div class="phrases-menu__key">
4
+ <%= phrase.code %>
5
+ </div>
6
+
7
+ <div class="phrases-menu__phrase">
8
+ <%= phrase.text %>
9
+ </div>
10
+ </div>
11
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Rosetta
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+
7
+ source_root File.expand_path('../../templates', __FILE__)
8
+
9
+ desc 'Creates a Rosetta initializer'
10
+
11
+ def copy_initializer
12
+ template 'rosetta.rb', 'config/initializers/rosetta.rb'
13
+ end
14
+
15
+ def rails_4?
16
+ Rails::VERSION::MAJOR == 4
17
+ end
18
+
19
+ end
20
+ end
21
+ end