go-aah / aah

A secure, flexible, rapid Go web framework
https://aahframework.org
MIT License
690 stars 33 forks source link

Add `aah generate i18n` command to generate i18n vars #119

Open julienkosinski opened 7 years ago

julienkosinski commented 7 years ago

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

adelowo commented 6 years ago

Wait, this would potentially scan through the entire codebase to determine the vars ? or how is this supposed to work ?

jeevatkm commented 6 years ago

@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:

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.

adelowo commented 6 years ago

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 ?

jeevatkm commented 6 years ago

@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?

adelowo commented 6 years ago

I would take a stab at it next week if it has not been worked on

jeevatkm commented 6 years ago

@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.

jeevatkm commented 5 years ago

This depends on #231