How to start internationalization in SolidJS with rosetta
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
I've stumbled on i18next while exploring thing topic. If I remember correctly, it's more complete library. Here I used Rosetta—it felt pretty simple/basic. It's good or bad depending on your needs. For small projects, I would start simple.
Are you working on a study project, or something bigger?
bigger Marcin Wosinek
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

In this article, I'll show how to add rosetta - small, but powerful i18n library to SolidJs application.
It is a minimalistic library that caught my attention when I was checking out what i18n libraries are out there - 5 libraries that looked interesting for me. Since then, I mostly experimented with i18next, but it feels a bit too big for many use cases.
An interesting, React-like framework that reached 1.0.0 in June this year.
To start a new application with Solid, the best way is to follow the documentation and use degit to copy an official project scaffolding:
$ npx degit solidjs/templates/js solidjs-rosetta
After starting the project, we should install its dependencies:
$ cd solidjs-rosetta
$ npm install
The only additional dependency we need is rosetta itself:
$ npm install --save rosetta
For starting my i18n, I'll replace the original src/App.jsx with:
import styles from "./App.module.css";
import rosetta from "rosetta";
const i18n = new rosetta({
en: {
hello: "Hello world!",
},
});
i18n.locale("en");
function App() {
return (
<div class={styles.App}>
<header class={styles.header}>{i18n.t("hello")}</header>
</div>
);
}
export default App;
The size difference between the build application with rosetta and the same with the translation hardcoded inside the view is:
# i18n with rosetta
dist/assets/index.54039bfe.js 1.14 KiB / brotli: 0.54 KiB
dist/assets/vendor.8b5da6db.js 5.73 KiB / brotli: 2.10 KiB
# harcoded value
dist/assets/index.153e60c6.js 1.07 KiB / brotli: 0.51 KiB
dist/assets/vendor.29e4bc78.js 5.29 KiB / brotli: 1.91 KiB
About 0.51 KiB - quite impressive, I would say.
With all that in place, the application should looks as follow:

In this article, we have built a simple infrastructure for adding multiple languages to an application based on Solid.