GithubHelp home page GithubHelp logo

kaspernj / awesome_translations Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 1.38 MB

Semi-automatic maintenance of most translations in a Rails app.

License: MIT License

Ruby 83.13% CSS 0.34% HTML 15.54% Liquid 0.25% JavaScript 0.18% SCSS 0.34% Haml 0.21%

awesome_translations's Introduction

Code Climate Test Coverage Build Status

AwesomeTranslations

Install

gem 'awesome_translations'
gem 'sqlite3', group: :development

AT uses SQLite3 for creating a database containing a farily large cache.

Then run the following:

bundle exec rake awesome_translations:install

Insert this into your "routes.rb" file:

mount AwesomeTranslations::Engine => "/awesome_translations" if Rails.env.development?

Translations under controllers and models

If you want to do translations from your models or controllers, you will need to add this to a new initializer file under "config/initializers/awesome_translations.rb"

AwesomeTranslations.load_object_extensions

If you don't like monkey patching the Object-class, you can also include it into ApplicationRecord' by inserting something like this to allow t-method-calls from inside models:

class ApplicationRecord < ActiveRecord::Base
  include AwesomeTranslations::TranslateFunctionality
end

You will also need to modify the line in your Gemfile a bit:

gem 'awesome_translations'

Helper translations

The t-method translates like from inside a view in Rails. To get around this, you can call 'helper_t' instead. Start by including that method in your helpers by adding this to ApplicationHelper:

module ApplicationHelper
  include AwesomeTranslations::ViewsHelper
end

Controller translations without action in key

Start by including this in your ApplicationController:

class ApplicationController
  include AwesomeTranslations::ControllerTranslateFunctionality

Then you can use the controller_t-method like this:

class UsersController < ApplicationController
  def create
    flash[:notice] = controller_t('.user_was_saved')
  end
end

This is an example of how it works and what the difference is:

module ApplicationHelper
  include AwesomeTranslations::ApplicationHelper

  # Sample method with translation
  def hello_world
    t('.hello_world') #=> translates with key '#{controller_name}.#{action_name}.hello_world'
    return helper_t('.hello_world') #=> translates with key 'helpers.application_helper.hello_world'
  end
end

Translating your application

Start a Rails server for your project and go to the namespace called something like "http://localhost:3000/awesome_translations". Start translating your app through the webinterface.

License

This project rocks and uses MIT-LICENSE.

awesome_translations's People

Contributors

danielfriis avatar dependabot-preview[bot] avatar dependabot[bot] avatar kaspernj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

awesome_translations's Issues

Helper module

Looks like helper-translations gets thrown under the current views key. Could be awesome if it was possible to change that into going under something like "helpers.tasks.#{key}" instead by calling the functionality in a initializer like with ObjectExtensions.

Rails 5 support

Currently awesome_translations depends on rails (< 5.0.0, >= 3.0.0). Would be awesome with Rails 5 support!

Show only unfinished translations

Maybe some sort of focus-mode where you're just presented one translation at a time. You do the translation, hit enter, and the next unfinished translation comes in focus.

Universal translation for model

Is it possible to specify a universal translation for a given model? For instance model_name.new_model_name, to be reused in several views.

Translations like that doesn't seem to appear in AT.

Spec support

Fail if any translations are removed from the code but not from the YML files.
Fail if any translations are missing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.