{"id":13879797,"url":"https://github.com/markets/mini_i18n","last_synced_at":"2025-04-07T12:10:41.694Z","repository":{"id":54194431,"uuid":"141349191","full_name":"markets/mini_i18n","owner":"markets","description":"🌐 Minimalistic I18n library for Ruby ","archived":false,"fork":false,"pushed_at":"2024-02-04T22:56:23.000Z","size":50,"stargazers_count":95,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T11:03:30.264Z","etag":null,"topics":["i18n","internationalization","micro-library","minimal","ruby","translations"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/mini_i18n","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markets.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-17T21:51:08.000Z","updated_at":"2024-12-31T01:55:02.000Z","dependencies_parsed_at":"2024-06-19T02:52:47.811Z","dependency_job_id":"f0b2c0f4-e3ca-481f-b91b-ef4e61b4f266","html_url":"https://github.com/markets/mini_i18n","commit_stats":{"total_commits":60,"total_committers":1,"mean_commits":60.0,"dds":0.0,"last_synced_commit":"32e8e5d9965d5463918be558b203446d471f2b7f"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fmini_i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fmini_i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fmini_i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fmini_i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markets","download_url":"https://codeload.github.com/markets/mini_i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","internationalization","micro-library","minimal","ruby","translations"],"created_at":"2024-08-06T08:02:33.693Z","updated_at":"2025-04-07T12:10:41.672Z","avatar_url":"https://github.com/markets.png","language":"Ruby","funding_links":[],"categories":["Ruby","Internationalization"],"sub_categories":[],"readme":"# `MiniI18n`\n\n[![Gem](https://img.shields.io/gem/v/mini_i18n.svg?style=flat-square)](https://rubygems.org/gems/mini_i18n)\n[![Build Status](https://github.com/markets/mini_i18n/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/markets/mini_i18n/actions)\n[![Maintainability](https://api.codeclimate.com/v1/badges/9d82e7151f8a5594da0f/maintainability)](https://codeclimate.com/github/markets/mini_i18n/maintainability)\n\n\u003e Minimalistic I18n library for Ruby\n\n`MiniI18n` is a simple, flexible and fast Ruby Internationalization library. It supports localization, interpolations, pluralization, fallbacks, nested keys and more.\n\nTranslations should be stored in `YAML` or `JSON` files and they will be loaded in an in-memory `Hash`.\n\n```yaml\nen:\n  hello: 'Hello'\n```\n\n```ruby\n\u003e\u003e MiniI18n.t(:hello)\n=\u003e \"Hello\"\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mini_i18n'\n```\n\nAnd then execute:\n\n    \u003e bundle install\n\nOr install it yourself as:\n\n    \u003e gem install mini_i18n\n\n## Usage\n\nYou should use the `configure` method to setup your environment:\n\n```ruby\nMiniI18n.configure do |config|\n  # Path to your translation files.\n  config.load_translations(__dir__ + '/translations/*')\n\n  # Default locale.\n  config.default_locale = :pt\n\n  # Available locales in your application.\n  config.available_locales = [:en, :es, :fr, :pt]\n\n  # If given key is empty, defaults to the default_locale.\n  config.fallbacks = true\n\n  # Custom separator for nested keys.\n  config.separator = '/'\n\n  # Custom pluralization rules, by locale.\n  config.pluralization_rules = {\n    es: -\u003e (n) { n == 0 ? 'zero' : 'other' },\n    fr: -\u003e (n) { ... }\n  }\nend\n```\n\nYou can also use the following format:\n\n```ruby\nMiniI18n.load_translations(__dir__ + '/translations/*')\nMiniI18n.default_locale = :en\n```\n\nExamples usage:\n\n```ruby\n\u003e\u003e MiniI18n.t(:hello)\n=\u003e \"Hello\"\n\u003e\u003e MiniI18n.t(:hello, locale: :fr)\n=\u003e \"Bonjour\"\n\u003e\u003e MiniI18n.locale = :fr\n=\u003e :fr\n\u003e\u003e MiniI18n.t(:hello)\n=\u003e \"Bonjour\"\n\u003e\u003e MiniI18n.t(:non_existent_key)\n=\u003e nil\n\u003e\u003e MiniI18n.t([:hello, :bye])\n=\u003e [\"Hello\", \"Bye\"]\n\u003e\u003e MiniI18n.t('app.controllers.not_found')\n=\u003e \"Not found!\"\n```\n\nThe `t` method can be also used as `translate`:\n\n```ruby\nMiniI18n.translate(:hello)\n```\n\nIt accepts the following options:\n\n* `locale`\n\n```ruby\n\u003e\u003e MiniI18n.t(:hello, locale: :es)\n=\u003e \"Hola\"\n```\n\nYou can also get multiple locales at once by passing an array:\n\n```ruby\n\u003e\u003e MiniI18n.t(:hello, locale: [:en, :fr, :es])\n=\u003e [\"Hello\", \"Bonjour\", \"Hola\"]\n```\n\n* `scope`\n\n```ruby\n\u003e\u003e MiniI18n.t('application.views.welcome')\n=\u003e \"Welcome\"\n\u003e\u003e MiniI18n.t('welcome', scope: 'application.views')\n=\u003e \"Welcome\"\n```\n\nRead more details about nested keys in [this section](#nested-keys).\n\n* `default`\n\n```ruby\n\u003e\u003e MiniI18n.t(:non_existent_key, default: 'default value')\n=\u003e \"default value\"\n```\n\n* `count`\n\n```ruby\n\u003e\u003e MiniI18n.t('notifications', count: 0)\n=\u003e \"no unread notifications\"\n```\n\nRead more details in the [Pluralization](#pluralization) section.\n\n### Nested Keys\n\nYou can use a custom separator when accessing nested keys (default separator is `.`):\n\n```yaml\nen:\n  app:\n    controllers:\n      not_found: \"Not found!\"\n```\n\n```ruby\nMiniI18n.t('app.controllers.not_found')\nMiniI18n.separator = '/'\nMiniI18n.t('app/controllers/not_found')\n```\n\n### Interpolation\n\nYou can also use variables in your translation definitions:\n\n```yaml\nen:\n  hello_with_name: \"Hello %{name}!\"\n```\n\n```ruby\n\u003e\u003e MiniI18n.t(:hello_with_name, name: 'John Doe')\n=\u003e \"Hello John Doe!\"\n```\n\n### Pluralization\n\nYou should define your plurals in the following format (default pluralization rule accepts the keys: `zero`, `one` and `other`):\n\n```yaml\nen:\n  notifications:\n    zero: 'good job! no new notifications'\n    one: '1 unread notification'\n    other: '%{count} unread notifications'\n```\n\nThen, you should call the method with the `count` option:\n\n```ruby\n\u003e\u003e MiniI18n.t('notifications', count: 0)\n=\u003e \"good job! no new notifications\"\n\u003e\u003e MiniI18n.t('notifications', count: 1)\n=\u003e \"1 unread notification\"\n\u003e\u003e MiniI18n.t('notifications', count: 5)\n=\u003e \"5 unread notifications\"\n```\n\n#### Custom pluralization rules\n\nYou are also able to customize how plurals are handled, by locale, defining custom pluralization rules. Example:\n\n```ruby\nMiniI18n.pluralization_rules = {\n  es: -\u003e (n) {\n    if n == 0\n      'zero'\n    elsif (1..3).include?(n)\n      'few'\n    elsif (4..10).include?(n)\n      'many'\n    else\n      'other'\n    end\n  }\n}\n```\n\nNow, in your translation files, you should define content for those keys:\n\n```yaml\nes:\n  notifications:\n    zero: 'no tienes nuevas notificaciones'\n    few: 'tienes algunas notificaciones pendientes ...'\n    many: 'tienes %{count} notificaciones!'\n    other: 'alerta!! %{count} notificaciones!'\n```\n\nAnd then, you get:\n\n```ruby\n\u003e\u003e MiniI18n.t('notifications', count: 0)\n=\u003e \"no tienes nuevas notificaciones\"\n\u003e\u003e MiniI18n.t('notifications', count: 2)\n=\u003e \"tienes algunas notificaciones pendientes ...\"\n\u003e\u003e MiniI18n.t('notifications', count: 5)\n=\u003e \"tienes 5 notificaciones!\"\n\u003e\u003e MiniI18n.t('notifications', count: 20)\n=\u003e \"alerta!! 20 notificaciones!\"\n```\n\n### Localization\n\nYou can also use the `MiniI18n.l` (or the long version `MiniI18n.localize`) method to localize your dates, time and numbers.\n\n#### Dates and time\n\nIt uses `strftime` under the hood. You should provide your localizations using the following format:\n\n```yaml\nen:\n  date:\n    formats:\n      default: \"%A %d, %B, %Y\"\n      short: \"%d %b %y\"\n```\n\n```ruby\n\u003e\u003e MiniI18n.l(Date.new(2018, 8, 15))\n=\u003e \"Wednesday 15, August, 2018\"\n\u003e\u003e MiniI18n.l(Date.new(2018, 8, 15), format: :short)\n=\u003e \"15 Aug 18\"\n```\n\nYou can check a full example of all necessary and useful keys [in this file](spec/fixtures/locales/localization.yml).\n\n#### Numbers\n\nTo localize your numbers, you can provide the following keys:\n\n```yaml\nen:\n  number:\n    format:\n      delimiter: ','\n      separator: '.'\n    as:\n      currency: '%{number} $'\n```\n\n```ruby\n\u003e\u003e MiniI18n.l(1000.25)\n=\u003e \"1,000.25\"\n\u003e\u003e MiniI18n.l(1000, as: :currency)\n=\u003e \"1,000 $\"\n\u003e\u003e MiniI18n.l(1000, as: :currency, locale: :es)\n=\u003e \"1.000 €\"\n```\n\n**TIP** By using the `:as` option you can build custom full sentences with formatted numbers, like:\n\n```yaml\nen:\n  number:\n    as:\n      final_price: 'Final price: %{number} $'\n      percentage: '%{number}%'\n```\n\n```ruby\n\u003e\u003e MiniI18n.l(1000, as: :final_price)\n=\u003e \"Final price: 1,000 $\"\n\u003e\u003e MiniI18n.l(70.5, as: :percentage)\n=\u003e \"70.5%\"\n```\n\n## Development\n\nAny kind of feedback, bug report, idea or enhancement are much appreciated.\n\nTo contribute, just fork the repo, hack on it and send a pull request. Don't forget to add specs for behaviour changes and run the test suite:\n\n    \u003e bundle exec rspec\n\n## License\n\nCopyright (c) Marc Anguera. MiniI18n is released under the [MIT](LICENSE) License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkets%2Fmini_i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkets%2Fmini_i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkets%2Fmini_i18n/lists"}