Skip to content

doc(localization): first draft [Solves #132]#15

Open
hleb-rubanau wants to merge 1 commit into
aldum:devfrom
hleb-rubanau:feature/132-internationalization-conventions-doc
Open

doc(localization): first draft [Solves #132]#15
hleb-rubanau wants to merge 1 commit into
aldum:devfrom
hleb-rubanau:feature/132-internationalization-conventions-doc

Conversation

@hleb-rubanau

Copy link
Copy Markdown
Collaborator

No description provided.

**`lang/en.lua`**
```lua
return {
["exercise.find_key.prompt"] = "Find this key: {key}",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question from @aldum :

  • ["exercise.find_key.prompt"] - these are literal keys, no hierarchy on the
    data structure level, right?

@hleb-rubanau hleb-rubanau May 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think actual best practice is three-layered:

  1. Translating: both nested and flat structures are allowed, i.e. two following approaches are equivalent:
excercise:
  find_key:
     prompt: value # naturally represents namespaces, best choice for big scopes of i18n pieces
excercise.find_key.prompt: value # also allowed, useful for scarce namespaces/thin configs
  1. When settings are loaded:
    Merge and resolve all i18n config pieces into a single structure -- either hierarchical structure or one with flattened keys (whatever suits best for internal representation and faster lookups -- most likely, flattened keys are)

  2. Lookup: use flat keys only, i.e. t("excercise.find_key.prompt"), and let translation engine to map key to its internal representation.

Lookup by flat keys has great practical bonus: it allows to easily return and display message key itself when nothing is found (or to display some normalized version of message key -- e.g. dots converted to spaces and first letters capitalized). Which is better than nothing and helps to easily troubleshoot malformed message keys.

Also, I must admit that if (most likely) external translators are used, I'd recommend to store translations in e.g. YAML file, rather than pure lua code, and load them into lua tables on initialization. But I am not sure if it meets current architectural vision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant