4 i18n
(ns index
(:require [dev.docs.dm :as dm]
[scicloj.kindly.v4.kind :as kind]))i18n is the component used to hold Oiiku’s i18n efforts together. This module is responsible for gathering the translations, handling inline translations (via reader tags) and validating that the the translations are correct. The rendering of the translations are handled via m1p, and the implementation details of those reside in the backend and the frontend respectively.
4.1 Rationale
i18n is a target for Oiiku, but as of yet not fully implemented. As a result, we have opted for an implementation with a clear path forward, but not fully commited as we so far only have one language.
4.2 Goals
- Clear path forward
- Markers where we want i18n, as this is the part that hurts to retroactively fit
- Do most of the work upfront, but with minimal impact on development
- Delay the actual translation into files for i18n consumption
- Support for advanced transformations (dictionary functions in m1p)
4.3 How?
A reader tag is introduced o/i18n. This hides the implementation details (dictionary functions still bleed through), marks the translations that needs to be done, scoops up the implementation details for automatic construction of the m1p dictionary and delays the translation.
The reader tag takes an expression which is a vector where the first argument is the i18n key, the second argument is the i18n value and the third argument is an optional i18n params map.
#o/i18n [:i18n.form.error/blank [:fn/str "{{:x}} can't be blank!"] {:x x}]
| i18n Expression | i18n Key | i18n Value | i18n Params |
|---|---|---|---|
| #o/i18n [:i18n.form.error/blank [:fn/str "{{:x}} can't be blank!"] {:x x}] | :i18n.form.error/blank | [:fn/str "{{:x}} can't be blank!"] | {:x x} |
| #o/i18n [:i18n.button/reset "Reset"] | :i18n.button/reset | Reset |
The i18n key ends up in a dictionary with the corresponding i18n value. For i18n values that are dictionary functions, the consumer of the i18n library has to handle that via m1p’s prepare-dictionary function.
4.4 Pancakes DM
How do we produce the best pankakes?
{:approach-order [:store-bought :ready-made-batter]
:dm {:store-bought
{:title "Store bought pancakes"
:summary "Ready made from the store"
:criteria {:price {:text "High"
:appeal :strong}
:easy "Very convenient, just go to the store"
:convenience "Super"}}
:ready-made-batter
{:price "Cheap"
:ease "Requires work"}}}{:approach-order [:store-bought :ready-made-batter],
:dm
{:store-bought
{:title "Store bought pancakes",
:summary "Ready made from the store",
:criteria
{:price {:text "High", :appeal :strong},
:easy "Very convenient, just go to the store",
:convenience "Super"}},
:ready-made-batter {:price "Cheap", :ease "Requires work"}}}| Best way to make pankakes | Make from scratch | Ready made batter | Store bought pancakes |
|---|---|---|---|
| Ready made batter bought from the store. Add water and start | Ready made from the store | ||
| How convenient is it? | |||
| Ease to make | |||
| Price | |||
| How tasty is it | Supper yummy | ||
| How much time is used? |
fo11
source: components/i18n/docs/index.clj