translate-rails3 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +62 -0
- data/Rakefile +33 -0
- data/VERSION +1 -0
- data/app/controllers/translate_controller.rb +165 -0
- data/app/helpers/translate_helper.rb +45 -0
- data/app/views/layouts/translate.html.erb +359 -0
- data/app/views/translate/_pagination.html.erb +24 -0
- data/app/views/translate/index.html.erb +114 -0
- data/config/routes.rb +5 -0
- data/init.rb +1 -0
- data/lib/tasks/translate.rake +178 -0
- data/lib/translate.rb +8 -0
- data/lib/translate/file.rb +35 -0
- data/lib/translate/keys.rb +152 -0
- data/lib/translate/log.rb +35 -0
- data/lib/translate/routes.rb +11 -0
- data/lib/translate/storage.rb +28 -0
- data/spec/controllers/translate_controller_spec.rb +130 -0
- data/spec/file_spec.rb +54 -0
- data/spec/files/translate/app/models/article.rb +12 -0
- data/spec/files/translate/app/views/category.erb +1 -0
- data/spec/files/translate/app/views/category.html +1 -0
- data/spec/files/translate/app/views/category.html.erb +1 -0
- data/spec/files/translate/app/views/category.rhtml +5 -0
- data/spec/files/translate/public/javascripts/application.js +1 -0
- data/spec/keys_spec.rb +179 -0
- data/spec/log_spec.rb +47 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/storage_spec.rb +33 -0
- data/translate-rails3.gemspec +77 -0
- metadata +118 -0
    
        data/spec/log_spec.rb
    ADDED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            require 'fileutils'
         | 
| 2 | 
            +
            require File.dirname(__FILE__) + '/spec_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe Translate::Log do
         | 
| 5 | 
            +
              describe "write_to_file" do
         | 
| 6 | 
            +
                before(:each) do
         | 
| 7 | 
            +
                  I18n.locale = :sv
         | 
| 8 | 
            +
                  I18n.backend.store_translations(:sv, from_texts)
         | 
| 9 | 
            +
                  keys = Translate::Keys.new
         | 
| 10 | 
            +
                  @log = Translate::Log.new(:sv, :en, Translate::Keys.to_shallow_hash(from_texts).keys)
         | 
| 11 | 
            +
                  @log.stub!(:file_path).and_return(file_path)
         | 
| 12 | 
            +
                  FileUtils.rm_f file_path
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
                after(:each) do
         | 
| 16 | 
            +
                  FileUtils.rm_f file_path
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                it "writes new log file with from texts" do
         | 
| 20 | 
            +
                  File.exists?(file_path).should be_false
         | 
| 21 | 
            +
                  @log.write_to_file
         | 
| 22 | 
            +
                  File.exists?(file_path).should be_true
         | 
| 23 | 
            +
                  Translate::File.new(file_path).read.should == Translate::File.deep_stringify_keys(from_texts)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
                it "merges from texts with current texts in log file and re-writes the log file" do
         | 
| 27 | 
            +
                  @log.write_to_file
         | 
| 28 | 
            +
                  I18n.backend.store_translations(:sv, {:category => "Kategori ny"})
         | 
| 29 | 
            +
                  @log.keys = ['category']
         | 
| 30 | 
            +
                  @log.write_to_file
         | 
| 31 | 
            +
                  Translate::File.new(file_path).read['category'].should == "Kategori ny"
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              
         | 
| 34 | 
            +
                def file_path
         | 
| 35 | 
            +
                  File.join(File.dirname(__FILE__), "files", "from_sv_to_en.yml")
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def from_texts
         | 
| 39 | 
            +
                  {
         | 
| 40 | 
            +
                    :article => {
         | 
| 41 | 
            +
                      :title => "En artikel"
         | 
| 42 | 
            +
                    },
         | 
| 43 | 
            +
                    :category => "Kategori"
         | 
| 44 | 
            +
                  }
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            begin
         | 
| 2 | 
            +
              # Using PWD here instead of File.dirname(__FILE__) to be able to symlink to plugin
         | 
| 3 | 
            +
              # from within a Rails app.
         | 
| 4 | 
            +
              require File.expand_path(ENV['PWD'] + '/../../../spec/spec_helper')
         | 
| 5 | 
            +
            rescue LoadError => e
         | 
| 6 | 
            +
              puts "You need to install rspec in your base app\n#{e.message}: #{e.backtrace.join("\n")}"
         | 
| 7 | 
            +
              exit
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            plugin_spec_dir = File.dirname(__FILE__)
         | 
| 11 | 
            +
            ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Translate::Storage do
         | 
| 4 | 
            +
              describe "write_to_file" do
         | 
| 5 | 
            +
                before(:each) do
         | 
| 6 | 
            +
                  @storage = Translate::Storage.new(:en)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
                it "writes all I18n messages for a locale to YAML file" do
         | 
| 10 | 
            +
                  I18n.backend.should_receive(:translations).and_return(translations)
         | 
| 11 | 
            +
                  @storage.stub!(:file_path).and_return(file_path)
         | 
| 12 | 
            +
                  file = mock(:file)
         | 
| 13 | 
            +
                  file.should_receive(:write).with(translations)
         | 
| 14 | 
            +
                  Translate::File.should_receive(:new).with(file_path).and_return(file)
         | 
| 15 | 
            +
                  @storage.write_to_file
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
                def file_path
         | 
| 19 | 
            +
                  File.join(File.dirname(__FILE__), "files", "en.yml")
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                def translations
         | 
| 23 | 
            +
                  {
         | 
| 24 | 
            +
                    :en => {
         | 
| 25 | 
            +
                      :article => {
         | 
| 26 | 
            +
                        :title => "One Article"
         | 
| 27 | 
            +
                      },
         | 
| 28 | 
            +
                      :category => "Category"
         | 
| 29 | 
            +
                    }
         | 
| 30 | 
            +
                  }
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,77 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{translate-rails3}
         | 
| 8 | 
            +
              s.version = "0.1.0"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Peter Marklund", "Milan Novota", "Roman Shterenzon"]
         | 
| 12 | 
            +
              s.date = %q{2011-05-09}
         | 
| 13 | 
            +
              s.description = %q{This plugin provides a web interface for translating Rails I18n texts
         | 
| 14 | 
            +
            (requires Rails 3.0 or higher) from one locale to another.
         | 
| 15 | 
            +
            The plugin has been tested only with the simple I18n backend that ships
         | 
| 16 | 
            +
            with Rails.
         | 
| 17 | 
            +
            I18n texts are read from and written to YAML files under config/locales.
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            This gem is a fork of the original https://github.com/mynewsdesk/translate
         | 
| 20 | 
            +
            and also includes work from this fork: https://github.com/milann/translate
         | 
| 21 | 
            +
            }
         | 
| 22 | 
            +
              s.email = %q{romanbsd@yahoo.com}
         | 
| 23 | 
            +
              s.extra_rdoc_files = [
         | 
| 24 | 
            +
                "README"
         | 
| 25 | 
            +
              ]
         | 
| 26 | 
            +
              s.files = [
         | 
| 27 | 
            +
                "MIT-LICENSE",
         | 
| 28 | 
            +
                "README",
         | 
| 29 | 
            +
                "Rakefile",
         | 
| 30 | 
            +
                "VERSION",
         | 
| 31 | 
            +
                "app/controllers/translate_controller.rb",
         | 
| 32 | 
            +
                "app/helpers/translate_helper.rb",
         | 
| 33 | 
            +
                "app/views/layouts/translate.html.erb",
         | 
| 34 | 
            +
                "app/views/translate/_pagination.html.erb",
         | 
| 35 | 
            +
                "app/views/translate/index.html.erb",
         | 
| 36 | 
            +
                "config/routes.rb",
         | 
| 37 | 
            +
                "init.rb",
         | 
| 38 | 
            +
                "lib/tasks/translate.rake",
         | 
| 39 | 
            +
                "lib/translate.rb",
         | 
| 40 | 
            +
                "lib/translate/file.rb",
         | 
| 41 | 
            +
                "lib/translate/keys.rb",
         | 
| 42 | 
            +
                "lib/translate/log.rb",
         | 
| 43 | 
            +
                "lib/translate/routes.rb",
         | 
| 44 | 
            +
                "lib/translate/storage.rb",
         | 
| 45 | 
            +
                "spec/controllers/translate_controller_spec.rb",
         | 
| 46 | 
            +
                "spec/file_spec.rb",
         | 
| 47 | 
            +
                "spec/files/translate/app/models/article.rb",
         | 
| 48 | 
            +
                "spec/files/translate/app/views/category.erb",
         | 
| 49 | 
            +
                "spec/files/translate/app/views/category.html",
         | 
| 50 | 
            +
                "spec/files/translate/app/views/category.html.erb",
         | 
| 51 | 
            +
                "spec/files/translate/app/views/category.rhtml",
         | 
| 52 | 
            +
                "spec/files/translate/public/javascripts/application.js",
         | 
| 53 | 
            +
                "spec/keys_spec.rb",
         | 
| 54 | 
            +
                "spec/log_spec.rb",
         | 
| 55 | 
            +
                "spec/spec_helper.rb",
         | 
| 56 | 
            +
                "spec/storage_spec.rb",
         | 
| 57 | 
            +
                "translate-rails3.gemspec"
         | 
| 58 | 
            +
              ]
         | 
| 59 | 
            +
              s.homepage = %q{https://github.com/romanbsd/translate}
         | 
| 60 | 
            +
              s.require_paths = ["lib"]
         | 
| 61 | 
            +
              s.rubygems_version = %q{1.3.7}
         | 
| 62 | 
            +
              s.summary = %q{Newsdesk translate plugin for Rails 3}
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              if s.respond_to? :specification_version then
         | 
| 65 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 66 | 
            +
                s.specification_version = 3
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 69 | 
            +
                  s.add_runtime_dependency(%q<ya2yaml>, ["~> 0.30"])
         | 
| 70 | 
            +
                else
         | 
| 71 | 
            +
                  s.add_dependency(%q<ya2yaml>, ["~> 0.30"])
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
              else
         | 
| 74 | 
            +
                s.add_dependency(%q<ya2yaml>, ["~> 0.30"])
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
| 77 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,118 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: translate-rails3
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              prerelease: false
         | 
| 5 | 
            +
              segments: 
         | 
| 6 | 
            +
              - 0
         | 
| 7 | 
            +
              - 1
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              version: 0.1.0
         | 
| 10 | 
            +
            platform: ruby
         | 
| 11 | 
            +
            authors: 
         | 
| 12 | 
            +
            - Peter Marklund
         | 
| 13 | 
            +
            - Milan Novota
         | 
| 14 | 
            +
            - Roman Shterenzon
         | 
| 15 | 
            +
            autorequire: 
         | 
| 16 | 
            +
            bindir: bin
         | 
| 17 | 
            +
            cert_chain: []
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            date: 2011-05-09 00:00:00 +03:00
         | 
| 20 | 
            +
            default_executable: 
         | 
| 21 | 
            +
            dependencies: 
         | 
| 22 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 23 | 
            +
              name: ya2yaml
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 26 | 
            +
                none: false
         | 
| 27 | 
            +
                requirements: 
         | 
| 28 | 
            +
                - - ~>
         | 
| 29 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 30 | 
            +
                    segments: 
         | 
| 31 | 
            +
                    - 0
         | 
| 32 | 
            +
                    - 30
         | 
| 33 | 
            +
                    version: "0.30"
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              version_requirements: *id001
         | 
| 36 | 
            +
            description: |
         | 
| 37 | 
            +
              This plugin provides a web interface for translating Rails I18n texts
         | 
| 38 | 
            +
              (requires Rails 3.0 or higher) from one locale to another.
         | 
| 39 | 
            +
              The plugin has been tested only with the simple I18n backend that ships
         | 
| 40 | 
            +
              with Rails.
         | 
| 41 | 
            +
              I18n texts are read from and written to YAML files under config/locales.
         | 
| 42 | 
            +
              
         | 
| 43 | 
            +
              This gem is a fork of the original https://github.com/mynewsdesk/translate
         | 
| 44 | 
            +
              and also includes work from this fork: https://github.com/milann/translate
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            email: romanbsd@yahoo.com
         | 
| 47 | 
            +
            executables: []
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            extensions: []
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            extra_rdoc_files: 
         | 
| 52 | 
            +
            - README
         | 
| 53 | 
            +
            files: 
         | 
| 54 | 
            +
            - MIT-LICENSE
         | 
| 55 | 
            +
            - README
         | 
| 56 | 
            +
            - Rakefile
         | 
| 57 | 
            +
            - VERSION
         | 
| 58 | 
            +
            - app/controllers/translate_controller.rb
         | 
| 59 | 
            +
            - app/helpers/translate_helper.rb
         | 
| 60 | 
            +
            - app/views/layouts/translate.html.erb
         | 
| 61 | 
            +
            - app/views/translate/_pagination.html.erb
         | 
| 62 | 
            +
            - app/views/translate/index.html.erb
         | 
| 63 | 
            +
            - config/routes.rb
         | 
| 64 | 
            +
            - init.rb
         | 
| 65 | 
            +
            - lib/tasks/translate.rake
         | 
| 66 | 
            +
            - lib/translate.rb
         | 
| 67 | 
            +
            - lib/translate/file.rb
         | 
| 68 | 
            +
            - lib/translate/keys.rb
         | 
| 69 | 
            +
            - lib/translate/log.rb
         | 
| 70 | 
            +
            - lib/translate/routes.rb
         | 
| 71 | 
            +
            - lib/translate/storage.rb
         | 
| 72 | 
            +
            - spec/controllers/translate_controller_spec.rb
         | 
| 73 | 
            +
            - spec/file_spec.rb
         | 
| 74 | 
            +
            - spec/files/translate/app/models/article.rb
         | 
| 75 | 
            +
            - spec/files/translate/app/views/category.erb
         | 
| 76 | 
            +
            - spec/files/translate/app/views/category.html
         | 
| 77 | 
            +
            - spec/files/translate/app/views/category.html.erb
         | 
| 78 | 
            +
            - spec/files/translate/app/views/category.rhtml
         | 
| 79 | 
            +
            - spec/files/translate/public/javascripts/application.js
         | 
| 80 | 
            +
            - spec/keys_spec.rb
         | 
| 81 | 
            +
            - spec/log_spec.rb
         | 
| 82 | 
            +
            - spec/spec_helper.rb
         | 
| 83 | 
            +
            - spec/storage_spec.rb
         | 
| 84 | 
            +
            - translate-rails3.gemspec
         | 
| 85 | 
            +
            has_rdoc: true
         | 
| 86 | 
            +
            homepage: https://github.com/romanbsd/translate
         | 
| 87 | 
            +
            licenses: []
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            post_install_message: 
         | 
| 90 | 
            +
            rdoc_options: []
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            require_paths: 
         | 
| 93 | 
            +
            - lib
         | 
| 94 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 95 | 
            +
              none: false
         | 
| 96 | 
            +
              requirements: 
         | 
| 97 | 
            +
              - - ">="
         | 
| 98 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 99 | 
            +
                  segments: 
         | 
| 100 | 
            +
                  - 0
         | 
| 101 | 
            +
                  version: "0"
         | 
| 102 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 103 | 
            +
              none: false
         | 
| 104 | 
            +
              requirements: 
         | 
| 105 | 
            +
              - - ">="
         | 
| 106 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 107 | 
            +
                  segments: 
         | 
| 108 | 
            +
                  - 0
         | 
| 109 | 
            +
                  version: "0"
         | 
| 110 | 
            +
            requirements: []
         | 
| 111 | 
            +
             | 
| 112 | 
            +
            rubyforge_project: 
         | 
| 113 | 
            +
            rubygems_version: 1.3.7
         | 
| 114 | 
            +
            signing_key: 
         | 
| 115 | 
            +
            specification_version: 3
         | 
| 116 | 
            +
            summary: Newsdesk translate plugin for Rails 3
         | 
| 117 | 
            +
            test_files: []
         | 
| 118 | 
            +
             |