aah
aah copied to clipboard
Add `aah generate i18n` command to generate i18n vars
Hello,
Besides aah generate
which could be used for whole generation about MVC (model needs database layer) I would like to present a functionality that I thought about i18n. The idea is to be able to generate a messages
file like below in this example:
For i18n, if I have i18n . "page.site.title.index"
in a view (so that's for each i18n
vars defined in view) , I will write in CLI aah generate i18n fr
, then it will generate a messages.fr
file with:
page {
site {
title {
index = ""
}
}
}
We already talked about that @jeevatkm in gitter, that's why it's already in roadmap. This issue is intended to precise it :).
Thank you very much! :D
Wait, this would potentially scan through the entire codebase to determine the vars
? or how is this supposed to work ?
@adelowo Thanks for asking.
This is an idea. As you know localizing application is considerable effort, aah CLI is gonna help on that. So command creates i18n placeholder then aah user fills in the locale based values in it.
Let's move on to implementation part:
Command: `aah generate i18n --importpath github.com/user/app --locale "en-US, fr, de-DE"`
Alias:` aah g i -i <value> -l <value>`
--importpath is optional if run from app directory tree
--locale creates `messages.{provided-locale}` file, if not provided then only creates the `messages.keys`
Steps:
- Command scans
views
directory and its sub-directories view files, uses the config from sectionview { ... }
such as file extension, delimiter, etc. - Looks for pattern
{{ i18n . "key" }}
- possible Regex would help us here - Writes the
messages.keys
file into directoryapp-base-dir/i18n
Sample messages.keys
content:
# PLEASE DO NOT EDIT
# It will be overwritten on next run
page {
site {
title {
index = "page.site.title.index"
}
}
}
Please let me know your thoughts.
Understood.... I am just more worried about updates. Does this plan to support update operations like running the command again after making some changes to the views - even though it was previously generated ?
@adelowo That's a good question and concern.
Yes, user can run n
no. of times. messages.keys
file would be overwritten on every run, since its one way. However locale message file would be appended with new keys.
BTW, Currently aahframework.org/config.v0
doesn't have persistence support yet. So before this implementation we have to added file persistence support for config values.
Would you like to try on it?
- Config file persistence support
- Command
aah generate i18n
I would take a stab at it next week if it has not been worked on
@adelowo I'm glad to hear that, No I'm not working on it. I have shared my idea with you today.
Currently I'm doing my homework on Websocket and Configurable roles/permissions for each route definition.
This depends on #231