para-i18n 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/para/admin/translation.coffee +3 -0
- data/app/assets/javascripts/para/i18n.coffee +1 -0
- data/app/controllers/para/admin/translations_controller.rb +44 -0
- data/app/views/para/admin/resources/_translations_form.html.haml +6 -0
- data/app/views/para/admin/translations/edit.html.haml +9 -0
- data/app/views/para/inputs/_i18n.html.haml +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/locales/para-i18n.fr.yml +5 -0
- data/lib/generators/para/i18n/form/form_generator.rb +31 -0
- data/lib/generators/para/i18n/form/templates/_translations_form.html.haml +8 -0
- data/lib/generators/para/i18n/translate/templates/model_migration.rb.erb +5 -0
- data/lib/generators/para/i18n/translate/translate_generator.rb +40 -0
- data/lib/para/i18n/engine.rb +39 -0
- data/lib/para/i18n/fallbacks.rb +15 -0
- data/lib/para/i18n/friendly_id.rb +63 -0
- data/lib/para/i18n/i18n_input.rb +29 -0
- data/lib/para/i18n/model.rb +67 -0
- data/lib/para/i18n/resources_table.rb +24 -0
- data/lib/para/i18n/translations_helper.rb +12 -0
- data/lib/para/i18n/version.rb +5 -0
- data/lib/para/i18n.rb +19 -0
- data/para-i18n.gemspec +25 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17b8bcf97585a99d6bdebb63fed2edb77b8ee5c8
|
4
|
+
data.tar.gz: 0c273413dfd04f84dea954ebe616e57873771314
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfa24b1fc36ecb0f04a82c6ae428109ef6a2d0fdb2f0a8347b28704aba7b06577c70d85fcbe5bc49d0fa5a3bc2efe73f426e4e11a1175dcd6a8cad812db039f6
|
7
|
+
data.tar.gz: c7c76befcdb61fec112409df695ddcde5523b3c5fb475bc39fb3220ef535cf516667192d2022663b5b4cc2a6c95201d570113079376b2a9b8cd981b32dd08420
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 vala
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Para::I18n
|
2
|
+
|
3
|
+
This gem allows for translating models content within the [Para](https://github.com/para-cms/para)
|
4
|
+
admin interface.
|
5
|
+
|
6
|
+
It works by adding a translations layer to ActiveRecord models, like Globalize
|
7
|
+
does, and with a similar API, but using JSON fields instead of tables.
|
8
|
+
|
9
|
+
**Note** : This gem only works with Postgres 9.4+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'para-i18n'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install para-i18n
|
26
|
+
|
27
|
+
Add the para-i18n javascript file to your app's admin manifest at `app/assets/javascripts/admin/app.(js|coffee)` :
|
28
|
+
|
29
|
+
```javascript
|
30
|
+
//= require para/i18n
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
To allow models to be translated, you need to add the `_translations:jsonb`
|
36
|
+
column to your model.
|
37
|
+
|
38
|
+
You can use the `para:i18n:translate` generator to generate the migration.
|
39
|
+
For example, to translate a page model :
|
40
|
+
|
41
|
+
```bash
|
42
|
+
rails generate para:i18n:translate page -m
|
43
|
+
```
|
44
|
+
|
45
|
+
Note that the `-m` option automatically migrates after the migration is
|
46
|
+
created.
|
47
|
+
|
48
|
+
Now that your model has the translations field in the table, juste use the
|
49
|
+
`translates` macro in your model to define which fields will be translated :
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class Page < ActiveRecord::Base
|
53
|
+
translates :title, :content
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Now, any `crud` component managing the `Page` model will show a button to access
|
58
|
+
the translation interface for existing entries.
|
59
|
+
|
60
|
+
## Overriding the translations form
|
61
|
+
|
62
|
+
The translation form can be overriden by generating it with the `para:i18n:form`
|
63
|
+
generator. This is useful to delete or add fields to translate that are not
|
64
|
+
properly displayed by the default view.
|
65
|
+
|
66
|
+
For example, the `Page` model translation form can be generated the following
|
67
|
+
way :
|
68
|
+
|
69
|
+
```bash
|
70
|
+
rails g para:i18n:form page
|
71
|
+
```
|
72
|
+
|
73
|
+
This will create a partial at `app/views/admin/pages/_translations_form.html.haml`
|
74
|
+
that you can override.
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/para-cms/para-i18n.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
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 @@
|
|
1
|
+
#= require ./admin/translation
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Para
|
2
|
+
module Admin
|
3
|
+
class TranslationsController < ::Para::Admin::CrudResourcesController
|
4
|
+
before_action :load_locales
|
5
|
+
|
6
|
+
def edit
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
if ::I18n.with_locale(@target_locale) { resource.update(resource_params) }
|
11
|
+
flash_message(:success, resource)
|
12
|
+
redirect_to after_form_submit_path
|
13
|
+
else
|
14
|
+
flash_message(:error, resource)
|
15
|
+
render 'edit'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def load_and_authorize_crud_resource
|
22
|
+
loader = self.class.cancan_resource_class.new(
|
23
|
+
self, :resource, class: resource_model
|
24
|
+
)
|
25
|
+
|
26
|
+
loader.load_and_authorize_resource
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_locales
|
30
|
+
@locales = ::I18n.available_locales - [::I18n.default_locale]
|
31
|
+
@target_locale = params[:target_locale] || @locales.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def resource_params
|
35
|
+
params.require(:resource).permit!
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_breadcrumbs
|
39
|
+
super
|
40
|
+
add_breadcrumb(t('para.i18n.translation'))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
= para_form_for(resource, url: @component.relation_path(resource, :translation)) do |form|
|
2
|
+
= form.fieldset do
|
3
|
+
- translated_model_fields_for(resource.class).each do |field|
|
4
|
+
= form.input field.field_name, as: :i18n, locale: @target_locale
|
5
|
+
|
6
|
+
= form.actions(except: :submit_and_add_another)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
= page_top_bar(title: resource_title_for(resource), type: 'crud/edit')
|
2
|
+
|
3
|
+
.page-content-wrap
|
4
|
+
.well
|
5
|
+
= form_tag @component.relation_path(resource, :translation, action: :edit), method: :get do
|
6
|
+
= label :target_locale, t('i18n_admin.translations.choose_locale')
|
7
|
+
= select_tag :target_locale, options_for_select(@locales.map { |locale| [locale, locale] }, @target_locale), data: { :'locale-select' => true }
|
8
|
+
|
9
|
+
= render find_partial_for(resource, :translations_form)
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "para/i18n"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'para/i18n/translations_helper'
|
2
|
+
|
3
|
+
module Para
|
4
|
+
module I18n
|
5
|
+
class FormGenerator < Para::Generators::NamedBase
|
6
|
+
include Para::Admin::BaseHelper
|
7
|
+
include Para::Generators::FieldHelpers
|
8
|
+
include Para::ModelHelper
|
9
|
+
include Para::I18n::TranslationsHelper
|
10
|
+
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
def generate_form
|
14
|
+
template(
|
15
|
+
"_translations_form.html.haml",
|
16
|
+
"app/views/admin/#{ plural_namespaced_path }/_translations_form.html.haml"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def translated_attributes
|
23
|
+
translated_model_fields_for(model)
|
24
|
+
end
|
25
|
+
|
26
|
+
def model
|
27
|
+
@model ||= Para.const_get(class_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
= para_form_for(resource, url: @component.relation_path(resource, :translation)) do |form|
|
2
|
+
= form.fieldset do
|
3
|
+
<%- translated_attributes.each do |field| -%>
|
4
|
+
= form.input :<%= field.field_name %>, as: :i18n, locale: @target_locale
|
5
|
+
<%- end -%>
|
6
|
+
|
7
|
+
= form.actions(except: :submit_and_add_another)
|
8
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
|
3
|
+
module Para
|
4
|
+
module I18n
|
5
|
+
class TranslateGenerator < Rails::Generators::NamedBase
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
include ActiveRecord::Generators::Migration
|
8
|
+
|
9
|
+
# Copied files come from templates folder
|
10
|
+
source_root File.expand_path('../templates', __FILE__)
|
11
|
+
|
12
|
+
class_option :migrate, type: :boolean, default: false, :aliases => "-m"
|
13
|
+
|
14
|
+
# Generator desc
|
15
|
+
desc "I18nAdmin translation generator"
|
16
|
+
|
17
|
+
def generate_migration
|
18
|
+
migration_template 'model_migration.rb.erb', "db/migrate/translate_#{ plural_file_name }.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def migrate
|
22
|
+
rake 'db:migrate' if options[:migrate]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def class_name
|
28
|
+
@class_name ||= super.gsub(/I18nAdmin::/, '')
|
29
|
+
end
|
30
|
+
|
31
|
+
def plural_class_name
|
32
|
+
@plural_class_name ||= class_name.pluralize
|
33
|
+
end
|
34
|
+
|
35
|
+
def table_name
|
36
|
+
@table_name ||= plural_class_name.underscore
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Para
|
2
|
+
module I18n
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
initializer 'para.i18n.include_model_extension_into_active_record' do
|
5
|
+
ActiveSupport.on_load(:active_record) do
|
6
|
+
include Para::I18n::Model
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer 'para.i18n.extend_para_routes' do
|
11
|
+
::Para.config.routes.extend_routes_for(:crud_component) do
|
12
|
+
resource :translation, only: [:edit, :update]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer 'para.i18n.include_view_helpers' do
|
17
|
+
ActiveSupport.on_load(:action_view) do
|
18
|
+
include Para::I18n::TranslationsHelper
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
initializer 'para.i18n.extend_para_resources_table' do
|
23
|
+
ActiveSupport.on_load(:action_view) do
|
24
|
+
::Para::Markup::ResourcesTable.send(:include, Para::I18n::ResourcesTable)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
initializer 'para.i18n.add_translate_actions' do
|
29
|
+
Para.config.add_actions_for('crud/edit') do
|
30
|
+
{
|
31
|
+
icon: 'globe',
|
32
|
+
label: ::I18n.t('para.i18n.translate'),
|
33
|
+
url: @component.relation_path(resource, :translation, action: :edit)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Para
|
2
|
+
module I18n
|
3
|
+
module Fallbacks
|
4
|
+
def self.i18n_fallback_for(locale)
|
5
|
+
return unless ::I18n.respond_to?(:fallbacks)
|
6
|
+
|
7
|
+
if (fallbacks = ::I18n.fallbacks[locale]) && fallbacks.length > 1
|
8
|
+
fallbacks[1]
|
9
|
+
else
|
10
|
+
::I18n.default_locale
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module FriendlyId
|
4
|
+
module I18n
|
5
|
+
class << self
|
6
|
+
def setup(model_class)
|
7
|
+
model_class.friendly_id_config.use :slugged
|
8
|
+
end
|
9
|
+
|
10
|
+
def included(model_class)
|
11
|
+
model_class.extend(ClassMethods)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_friendly_id(text, locale = nil)
|
16
|
+
::I18n.with_locale(locale || ::I18n.locale) do
|
17
|
+
set_slug(normalize_friendly_id(text))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def should_generate_new_friendly_id?
|
22
|
+
translation_for(::I18n.locale)[friendly_id_config.slug_column].blank?
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_slug(normalized_slug = nil)
|
26
|
+
return unless should_generate_new_friendly_id?
|
27
|
+
|
28
|
+
candidates = FriendlyId::Candidates.new(self, normalized_slug || send(friendly_id_config.base))
|
29
|
+
slug = slug_generator.generate(candidates) || resolve_friendly_id_conflict(candidates)
|
30
|
+
self.slug = slug
|
31
|
+
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
def exists_by_friendly_id?(id)
|
35
|
+
if (exists = by_friendly_id(id).exists?)
|
36
|
+
exists
|
37
|
+
elsif (fallback_locale = Para::I18n::Fallbacks.i18n_fallback_for(::I18n.locale))
|
38
|
+
by_friendly_id(id, fallback_locale).exists?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def first_by_friendly_id(id)
|
45
|
+
if (first = by_friendly_id(id).first)
|
46
|
+
first
|
47
|
+
elsif (fallback_locale = Para::I18n::Fallbacks.i18n_fallback_for(::I18n.locale))
|
48
|
+
by_friendly_id(id, fallback_locale).first
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def by_friendly_id(id, locale = ::I18n.locale)
|
53
|
+
if locale == ::I18n.default_locale
|
54
|
+
where(friendly_id_config.query_field => id)
|
55
|
+
else
|
56
|
+
json_path = "{#{ ::I18n.locale },#{ friendly_id_config.query_field }}"
|
57
|
+
where("_translations#>>'#{ json_path }' = ?", id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Para
|
2
|
+
module Inputs
|
3
|
+
class I18nInput < SimpleForm::Inputs::Base
|
4
|
+
def input(wrapper_options = nil)
|
5
|
+
model = object.class
|
6
|
+
|
7
|
+
template.render(
|
8
|
+
partial: 'para/inputs/i18n',
|
9
|
+
locals: {
|
10
|
+
form: @builder,
|
11
|
+
resource: object,
|
12
|
+
attribute_name: attribute_name,
|
13
|
+
locale: locale
|
14
|
+
}
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def locale
|
21
|
+
if (locale = options[:locale])
|
22
|
+
locale
|
23
|
+
else
|
24
|
+
raise 'Missing `:locale` option passed to :i18n input.'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Para
|
2
|
+
module I18n
|
3
|
+
module Model
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :translated_fields
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_translated_attribute(field, locale = ::I18n.locale)
|
11
|
+
return read_attribute(field) if locale == ::I18n.default_locale
|
12
|
+
|
13
|
+
if model_translations[locale.to_s]
|
14
|
+
if (translation = model_translations[locale.to_s][field.to_s])
|
15
|
+
return translation
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# If no translation was returned, try to fallback to the next locale
|
20
|
+
if (fallback_locale = Fallbacks.i18n_fallback_for(locale))
|
21
|
+
read_translated_attribute(field, fallback_locale)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def write_translated_attribute field, value, locale = ::I18n.locale
|
26
|
+
return write_attribute(field, value) if locale == ::I18n.default_locale
|
27
|
+
|
28
|
+
model_translations[locale.to_s] ||= {}
|
29
|
+
model_translations[locale.to_s][field.to_s] = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def model_translations
|
33
|
+
unless respond_to?(:_translations)
|
34
|
+
raise "The model #{ self.class.name } is not translatable. " +
|
35
|
+
"Please run `rails g i18n_admin:translate #{ self.model_name.element }` " +
|
36
|
+
"generator to create the model's migration."
|
37
|
+
end
|
38
|
+
|
39
|
+
self._translations ||= {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def translation_for(locale)
|
43
|
+
model_translations[locale] || {}
|
44
|
+
end
|
45
|
+
|
46
|
+
module ClassMethods
|
47
|
+
def translates(*fields)
|
48
|
+
self.translated_fields = fields.map(&:to_sym)
|
49
|
+
|
50
|
+
fields.each do |field|
|
51
|
+
define_method field do
|
52
|
+
read_translated_attribute(field)
|
53
|
+
end
|
54
|
+
|
55
|
+
define_method :"#{ field }=" do |value|
|
56
|
+
write_translated_attribute(field, value)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def translatable?
|
62
|
+
translated_fields.length > 0
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Para
|
2
|
+
module I18n
|
3
|
+
module ResourcesTable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
last_action = default_actions.pop
|
8
|
+
default_actions << :translate
|
9
|
+
default_actions << last_action
|
10
|
+
end
|
11
|
+
|
12
|
+
def translate_button(resource)
|
13
|
+
return unless resource.class.translatable?
|
14
|
+
|
15
|
+
path = component.relation_path(resource, :translation, action: :edit)
|
16
|
+
options = { class: 'btn btn-info' }
|
17
|
+
|
18
|
+
view.link_to(path, options) do
|
19
|
+
content_tag(:i, '', class: 'fa fa-globe')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Para
|
2
|
+
module I18n
|
3
|
+
module TranslationsHelper
|
4
|
+
# TODO : Support images & co
|
5
|
+
def translated_model_fields_for(model)
|
6
|
+
model_field_mappings(model).fields.select do |field|
|
7
|
+
model.translated_fields.include?(field.name.to_sym)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/para/i18n.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'para/i18n/version'
|
2
|
+
|
3
|
+
require 'para/i18n/fallbacks'
|
4
|
+
|
5
|
+
require 'para/i18n/model'
|
6
|
+
require 'para/i18n/resources_table'
|
7
|
+
require 'para/i18n/translations_helper'
|
8
|
+
|
9
|
+
require 'para/i18n/friendly_id'
|
10
|
+
|
11
|
+
require 'para/i18n/i18n_input'
|
12
|
+
|
13
|
+
require 'para/i18n/engine'
|
14
|
+
|
15
|
+
module Para
|
16
|
+
module I18n
|
17
|
+
# Your code goes here...
|
18
|
+
end
|
19
|
+
end
|
data/para-i18n.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'para/i18n/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "para-i18n"
|
8
|
+
spec.version = Para::I18n::VERSION
|
9
|
+
spec.authors = ["Valentin Ballestrino"]
|
10
|
+
spec.email = ["vala@glyph.fr"]
|
11
|
+
|
12
|
+
spec.summary = %q{Para CMS I18n admin module for models}
|
13
|
+
spec.description = %q{Para CMS I18n admin module for models}
|
14
|
+
spec.homepage = "https://github.com/para-cms/para-i18n"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: para-i18n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Valentin Ballestrino
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Para CMS I18n admin module for models
|
56
|
+
email:
|
57
|
+
- vala@glyph.fr
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- app/assets/javascripts/para/admin/translation.coffee
|
70
|
+
- app/assets/javascripts/para/i18n.coffee
|
71
|
+
- app/controllers/para/admin/translations_controller.rb
|
72
|
+
- app/views/para/admin/resources/_translations_form.html.haml
|
73
|
+
- app/views/para/admin/translations/edit.html.haml
|
74
|
+
- app/views/para/inputs/_i18n.html.haml
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
77
|
+
- config/locales/para-i18n.fr.yml
|
78
|
+
- lib/generators/para/i18n/form/form_generator.rb
|
79
|
+
- lib/generators/para/i18n/form/templates/_translations_form.html.haml
|
80
|
+
- lib/generators/para/i18n/translate/templates/model_migration.rb.erb
|
81
|
+
- lib/generators/para/i18n/translate/translate_generator.rb
|
82
|
+
- lib/para/i18n.rb
|
83
|
+
- lib/para/i18n/engine.rb
|
84
|
+
- lib/para/i18n/fallbacks.rb
|
85
|
+
- lib/para/i18n/friendly_id.rb
|
86
|
+
- lib/para/i18n/i18n_input.rb
|
87
|
+
- lib/para/i18n/model.rb
|
88
|
+
- lib/para/i18n/resources_table.rb
|
89
|
+
- lib/para/i18n/translations_helper.rb
|
90
|
+
- lib/para/i18n/version.rb
|
91
|
+
- para-i18n.gemspec
|
92
|
+
homepage: https://github.com/para-cms/para-i18n
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Para CMS I18n admin module for models
|
116
|
+
test_files: []
|