airbnb / polyglot.js

Give your JavaScript the ability to speak many languages.
http://airbnb.github.io/polyglot.js
BSD 2-Clause "Simplified" License
3.71k stars 208 forks source link

Best practise to handle missing interpolation values? #103

Open Strajk opened 6 years ago

Strajk commented 6 years ago

As a developer, I would like to know when I forget to provide interpolation values. Do you have some best practice to do that?

Throwing exception is probably too much, but a warning is too little :)

polyglot.extend({
  "hello_name": "Hola, %{name}."
});

polyglot.t("hello_name", {});
=> "Hola, %{name}." // => 💣💥
ljharb commented 6 years ago

Sometimes this is intentional - for example, if you're sending a partially interpolated string from the server to the browser to finish there. Do you have a suggestion?

In general tho this seems like the kind of thing that's addressed with testing.