Project

i18n-ai

0.01
There's a lot of open issues
i18n-ai is a gem that converts your locales into different languages automatically
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 6.0.0, < 8
 Project Readme

i18n-ai

i18n-ai is a gem that converts your rails locales into different languages automatically. Uses the en.yml file as base by default and creates accompanying es.yml, it.yml and others depending on your configuration.

Support for different AI services and models are available. You can use OpenAI, Anthropic Claude or even local services.

Installation

Simply add to your gemfile:

gem "i18n-ai"

And do bundle install.

Configuration

To use I18nAi, you need to set the appropriate environment variables based on the AI service you wish to use.

OpenAI

If you are using OpenAI, set ENV["OPENAI_ACCESS_TOKEN"]

To configure and enable other locales, create a file config/initializers/i18n_ai.rb and add the following:

# config/initializers/i18n_ai.rb
I18nAi.configure do |config|
  config.ai_settings = {
    provider: "openai",
    model: "gpt-4o-mini",
    access_token: ENV["OPENAI_ACCESS_TOKEN"]
  }
  config.generate_locales = [:es, :it] # add your other supported locales to this array
end

Anthropic Claude

If you prefer to use Anthropic's Claude, set ENV[ANTHROPIC_API_KEY]

To configure and enable other locales, create a file config/initializers/i18n_ai.rb and add the following:

I18nAi.configure do |config|
  config.ai_settings = {
    provider: "anthropic",
    model: "claude-3-haiku-20240307",
    access_token: ENV["ANTHROPIC_ACCESS_TOKEN"]
  }
  config.generate_locales = [:es]
end

Local

You can also use local AI models that use the OpenAI API. Tested locally with ollama together with mistral and llama3 models.

To configure and enable other locales, create a file config/initializers/i18n_ai.rb and add the following:

I18nAi.configure do |config|
  config.ai_settings = {
    provider: "local",
    model: "mistral",
    url: "http://localhost:11434/api/generate"
  }
  config.generate_locales = [:es]
end

Warning

Make sure to use the completions vs chat API endpoint as the URL value.

Usage

Every page reload, the gem will check if the en.yml file changed and if it did, it will automatically generate the configured locale files.

The gem has been setup to generate a es.yml file by default.

To disable locale generation simply set the generate_locales to an empty array.

I18nAi.configure do |config|
  config.generate_locales = []
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the I18n::Ai project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.