• Stars
    star
    39
  • Rank 693,563 (Top 14 %)
  • Language
    Crystal
  • License
    MIT License
  • Created over 3 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.

Rosetta

Rosetta logo

A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup. You'll never have a missing translation in your app, ever again.

GitHub GitHub tag (latest SemVer) GitHub Workflow Status

Why use Rosetta?

You'll never have a missing translation

Rosetta is different from other internationalization libraries because it handles key lookup at compile-time rather than runtime. The significant advantage is that you'll be able to find missing translations - or typos in your locale keys - during development rather than after you've deployed your app. This is also true for translation keys in all additional locales.

You'll never have a missing interpolation

In Rosetta, interpolation keys are arguments to the translation method. So if you're missing an argument, the compiler will complain. The parser will also compare interpolation keys in additional locales to the ones found in the default locale, and complain if some are missing.

Rosetta is more than 12x faster than similar libraries

Benchmarking against other libraries which also use YAML or JSON backends, Rosetta is 12x to 700x faster than any other one.

For simple translations:

crimson-knight/i18n.cr translation 303.57k (  3.29µs) (± 4.62%)  801B/op  702.21× slower
     crystal-i18n/i18n translation  18.07M ( 55.35ns) (± 7.28%)  48.0B/op  12.39× slower
         syeopite/lens translation   5.09M (196.47ns) (± 4.60%)   176B/op  43.98× slower
          wout/rosetta translation 223.86M (  4.47ns) (± 2.20%)   0.0B/op        fastest

For translations with interpolations:

crimson-knight/i18n.cr interpolation 318.12k (  3.14µs) (± 0.85%)    801B/op  108.51× slower
     crystal-i18n/i18n interpolation  65.55k ( 15.26µs) (± 1.01%)  28.2kB/op  664.37× slower
         syeopite/lens interpolation   2.04M (490.17ns) (± 1.35%)    565B/op   21.35× slower
          wout/rosetta interpolation  43.55M ( 22.96ns) (± 4.81%)   80.0B/op         fastest

Rosetta is that much faster because a lot of the hard work happens at compile-time. And because the majority of the data is stored on the stack rather than the heap, out of the scope of garbage collector.

Read more on the official docs page.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  rosetta:
    github: wout/rosetta
  1. Run shards install

  2. Run bin/rosetta --init

  3. Require the generated config file:

# src/app_name.cr
require "../config/rosetta"
  1. Include the Rosetta::Translatable mixin:
# src/pages/main_layout.cr
include Rosetta::Translatable
  1. Localize your app
Rosetta.locale = :es

class Hello::ShowPage < MainLayout
  def content
    h1 r("welcome_message").t(name: "Brian") # => "¡Hola Brian!"
  end
end

Read more on the official docs page.

Development

Make sure you have Guardian.cr installed. Then run:

$ guardian

This will automatically:

  • run ameba for src and spec files
  • run the relevant spec for any file in src
  • run spec file whenever they are saved
  • install shards whenever you save shard.yml

Documentation

Contributing

To the lib

  1. Fork it (https://github.com/wout/rosetta/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

To the docs

Check out the docs branch and run the following command to launch the docs locally:

docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material

Contributors

  • wout - creator and maintainer

Acknowledgements

This shard pulls inspiration from the following projects:

More Repositories

1

raphael-svg-import

Import raw SVG data into Raphael
JavaScript
260
star
2

chronology.js

A micro javascript library for managing an undo/redo history
JavaScript
45
star
3

base_x

A Crystal shard for base encoding / decoding of any given alphabet with optional bitcoin-style leading zero compression.
Crystal
12
star
4

lucky_vite

A Crystal shard to seamlessly integrate Vite with Lucky Framework
Crystal
7
star
5

dat-metadata-standard

A metadata standard for storing Distributed Artifact Tokens, or DATs, on the Cardano blockchain.
6
star
6

dendro

The source code for the DendroRithms generator
Crystal
5
star
7

mailjet.cr

Mailjet API Client for Crystal https://app.mailjet.com
Crystal
4
star
8

innate.js

A micro library eliminating the need for jQuery in most common tasks.
JavaScript
4
star
9

lucky_svg_sprite

Generate sanitized SVG icon sprites as Lucky-flavored components from folders of separate icons.
Crystal
4
star
10

packlink.cr

Packlink API client for Crystal https://pro.packlink.com
Crystal
4
star
11

spec_mirror.cr

Develoment utility to run a mirroring spec whenever a source file is saved.
Crystal
3
star
12

lucky_favicon

Add favicons from the Real Favicon Generator to your Lucky project.
Crystal
3
star
13

svg.onchain.js

A micro JS library for manipulating and animating SVG.
JavaScript
3
star
14

trustfeed.js

A library-agnostic micro API wrapper for Trustpilot.
JavaScript
2
star
15

vite-plugin-lucky

A plugin for using Vite with Lucky Framework
TypeScript
2
star
16

cardano_json_api

A JSON:API-compliant REST API for the Cardano blockchain built with Crystal and Lucky Framework
Crystal
2
star
17

kdtree.onchain.js

A micro JS library for building K-Dimensional Trees with N-Nearest Neighbours Search.
JavaScript
2
star
18

go_squared

A Ruby Gem wrapping the gosquared.com API
Ruby
2
star
19

bezier.onchain.js

A micro JS library for building SVG bezier paths from an arrays of points.
JavaScript
2
star
20

venster-examples

A repo with example implementations of the DAT Metadata Standard.
JavaScript
1
star
21

easing.onchain.js

A micro JS library for falloffs using various easing methods.
JavaScript
1
star
22

MediumAsMessage

Website for mediumasmessage.xyz
HTML
1
star
23

rate_limiter

A rate limiter implementation in Crystal
Crystal
1
star
24

cardano-kit

At toolkit for Crystal to ease development for the Cardano blockchain.
Crystal
1
star
25

svg.fromhtml.js

A plugin for svg.js library converting HTML into SVG
1
star
26

venster-external-dependencies

Venster's external dependencies for on-chain browser-based DATs.
1
star
27

venster-internal-assets

A repo holding all internal assets of venster.io
1
star
28

bech32

A BIP173/BIP350 compatible Bech32/Bech32m encoding/decoding library for Crystal.
Crystal
1
star
29

matrix.onchain.js

A micro JS library for matrix operations.
JavaScript
1
star
30

lucky_svg_sprite_cli

CLI to generate Lucky Framework-flavored SVG icon sprite components from a folder of icons.
Crystal
1
star
31

venster-docs

Documentation page for the venster app and DAT metadata standard
CSS
1
star
32

svg.adopt.js

A plugin for the svg.js library adopt existing inline svg's
1
star
33

wout.github.io

SVG.js website
HTML
1
star
34

circle.onchain.js

A micro JS library with circle-related utility functions.
JavaScript
1
star
35

prng.onchain.js

A micro JS implementation of the Mulberry32 seedable pseudorandom number generator.
JavaScript
1
star
36

svg_chok

A micro app to visualise Sverchok SVG output.
Crystal
1
star