A Ruby implementation of Project Fluent - a modern localization system designed to improve how software is translated.
- fluent.js compatibility - 159/160 official test fixtures passing
- Runtime message formatting - Bundle system with
icu4x-based formatting - FTL syntax parser - Syntax support with error recovery
- Multi-language support - Number, date, and pluralization formatting
- CLI tools - Lint and validate FTL files
- Ruby implementation - API following Ruby conventions
Add this line to your application's Gemfile:
gem "foxtail"And then execute:
$ bundle installOr install it yourself as:
$ gem install foxtailFoxtail uses the icu4x gem (Ruby bindings for ICU4X), which requires data configuration:
- The
icu4x-data-recommendedgem is included as a development dependency - Run
bin/setupto configure theICU4X_DATA_PATHenvironment variable in.env
For details, see the icu4x gem documentation.
require "foxtail"
require "icu4x"
resource = Foxtail::Resource.from_string(<<~FTL)
hello = Hello, { $name }!
emails =
You have { $count ->
[one] one email
*[other] { $count } emails
}.
FTL
bundle = Foxtail::Bundle.new(ICU4X::Locale.parse("en-US"))
bundle.add_resource(resource)
bundle.format("hello", name: "Alice")
# => "Hello, Alice!"
bundle.format("emails", count: 1)
# => "You have one email."
bundle.format("emails", count: 5)
# => "You have 5 emails."See the examples/ directory for executable demonstrations:
- Basic features: Variables, selectors, terms, attributes
- Number/Date formatting: Currency, percent, date styles
- Custom functions: Adding your own formatters
- Multi-language apps: Language fallback with
Sequence - E-commerce: Real-world pricing and cart localization
- Dungeon Game: Advanced item localization with grammatical gender/case (German), elision (French), and counter words (Japanese)
After checking out the repo, run:
$ bin/setupThis will install dependencies and set up the fluent.js submodule for compatibility testing.
# Run all tests
$ bundle exec rake spec# Run all checks (tests + linting)
$ bundle exec rake- Parser System - FTL syntax parsing and AST implementation
- Bundle System - Runtime message formatting with icu4x integration
- Sequence - Language fallback chains
See doc/architecture.md for detailed design documentation.
Foxtail provides command-line tools for working with FTL files:
foxtail check- Check FTL files for syntax errorsfoxtail dump- Dump FTL files as AST in JSON formatfoxtail ids- Extract message and term IDsfoxtail tidy- Format FTL files with consistent style
See doc/cli.md for full documentation.
- Ruby: 3.2 or higher
- fluent.js: 159/160 test fixtures passing (99.4%)
- Syntax parser: 97/98 (99.0%)
- Bundle parser: 62/62 (100%)
Bug reports and pull requests are welcome on GitHub at https://github.com/sakuro/foxtail.
- Fork it
- Create your feature branch (
git checkout -b feature/add-some-feature) - Run the tests (
bundle exec rake spec) - Commit your changes (
git commit -am ':sparkles: Add some feature') - Push to the branch (
git push origin feature/add-some-feature) - Create new Pull Request
This project stands on the shoulders of giants:
- ICU4X: Number, date/time, plural rules, and locale handling
- Fluent Project: Foxtail aims for compatibility with Mozilla's Fluent localization system, particularly fluent.js (Apache 2.0)
The gem is available as open source under the terms of the MIT License.