Skip to content

Search modules for message files as well #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2016

Conversation

notzippy
Copy link
Collaborator

This patch searches the modules for message files as well. This enhances modules so they can also provide translations with the packages.

Signed-off-by: NotZippy <notzippy@gmail.com>
@brendensoares brendensoares added this to the v0.12 milestone Jan 1, 2015
@brendensoares
Copy link
Member

@notzippy can you please provide steps to verify that this works from a new app to the expected results?

Please & thank you.

@brendensoares brendensoares self-assigned this Jan 1, 2015
@notzippy
Copy link
Collaborator Author

notzippy commented Jan 1, 2015

Steps, I create a module called bar and add a messages/test.en file to it to translate helloworld. Note this just adds <b>A friendly {{msg . "helloworld"}}</b> to the created view in the application, in the real world messages in the module should be normally only used in that module.

revel new temp/foo
mkdir -p $GOPATH/src/temp/foo/modules/bar/messages
echo "helloworld=Hi there"> $GOPATH/src/temp/foo/modules/bar/messages/test.en
echo "module.bar=temp/foo/modules/bar" >>$GOPATH/src/temp/foo/conf/app.conf
echo "<b>A friendly {{msg . \"helloworld\"}}</b>" >> $GOPATH/src/temp/foo/app/views/App/Index.html 
revel run temp/foo prod

(Had to run in production mode since the module is appended to the production section of the app.conf)

Additional notes,

  1. It is expected that the developer follow the same guidelines with the messages as they would with the views, ie prefix all the messages with something appropriate which would not conflict with another message since these are appended to the "global" message queue

@ghost
Copy link

ghost commented Jan 2, 2015

So, here is a short summary:
Revel can import from modules (http://revel.github.io/manual/modules.html):

  1. templates
  2. controllers
  3. routes
  4. assets (using Static.ServeModule method).
    This PR makes it possible to import i18n files, too. @notzippy Is my understanding correct?

casting @pedromorgan

@notzippy
Copy link
Collaborator Author

notzippy commented Jan 2, 2015

Yes this allows modules to declare there own 18n messages. I was not aware
that routes could be defined in a module, how does one so that?

On Fri, Jan 2, 2015, 6:41 AM anonx notifications@github.com wrote:

So, here is a short summary:
Revel can import from modules (
http://revel.github.io/manual/modules.html):

  1. templates
  2. controllers
  3. routes
  4. assets (using Static.ServeModule method).
    This PR makes it possible to import i18n files, too. @notzippy
    https://github.com/notzippy Is my understanding correct?

cast @pedromorgan https://github.com/pedromorgan


Reply to this email directly or view it on GitHub
#828 (comment).

@ghost
Copy link

ghost commented Jan 2, 2015

@notzippy To import routes from the module, update your app's config/routes: https://github.com/revel/revel/blob/master/samples/booking/conf/routes#L5 or #422.

@brendensoares
Copy link
Member

@AnonX @notzippy importing module routes is in the Revel manual under "Routing Modules".

@notzippy
Copy link
Collaborator Author

notzippy commented Jan 2, 2015

@brendensoares @AnonX thx, learn something new every day...

@@ -91,6 +91,14 @@ func loadMessages(path string) {
if error := filepath.Walk(path, loadMessageFile); error != nil && !os.IsNotExist(error) {
ERROR.Println("Error reading messages files:", error)
}

// Read in messages from the modules
for _, module := range Modules {
Copy link
Member

Choose a reason for hiding this comment

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

It may be better to add a MessagesPaths similar to TemplatePaths in revel.go instead of accessing Modules directly. Thoughts? It's a minor difference, but more consistent with the current module convention.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Messages is a different beast to begin with. It is loaded through an init method and OnAppStart. Templates are loaded in server.go:run. To me neither seem totally correct, exposing TemplatePaths seems unnecessary (as does ConfPaths and CodePaths). My thoughts are that the revel:addModule method should have a callBack list of items to be notified when a module is added, (with the possibility of adding more callbacks in the config). Each item then would take care of initializing its own area. However I do not want to even look at this until after we have broken completed the breaking up of revel.

For the intermediate time though I think this is a valuable PR even if it is not implemented in the same way as the templates.

@pedromorgan
Copy link
Member

@brendensoares Can u merge the develop branch into master ASAP, people are referinging stuff.. and we need to go!!!!!!!!!!!!

or shall i commit to master myself.. he thinks !!!

@brendensoares
Copy link
Member

@pedromorgan what do you mean "referinging stuff"?

Don't merge into master, that would break our workflow. The Roadmap for v0.12 has been reduced, we just need to finish it up and then we can merge into master and release develop. There isn't much effort needed before we can release v0.12.

@notzippy
Copy link
Collaborator Author

notzippy commented Feb 9, 2015

Will this make the 0.12 release ? Or will it be deferred till later ?

@brendensoares
Copy link
Member

brendensoares commented Mar 2, 2015

@notzippy No, this PR is not the correct way to go about loading i18n files in modules.

We can still use this PR, but we need to make some changes.

TODO

  • Track a MessagesPath in revel.go's func addModule(name, importPath, modulePath string) that i18n.go can search for messages files.

I'm rescheduling this for the next release as we don't have time to update this PR and reverify it. v0.12 needs to get buttoned up and out the door.

@brendensoares brendensoares modified the milestones: v0.13, v0.12 Mar 2, 2015
@ghost
Copy link

ghost commented Mar 2, 2015

@brendensoares We are using Modules directly in static module BTW: https://github.com/revel/revel/blob/master/modules/static/app/controllers/static.go#L66
The only difference is here messages are scanned once (on bootstrap time). And static is iterating over modules on every request which is not really cool if we have many modules.

@notzippy
Copy link
Collaborator Author

notzippy commented Mar 2, 2015

@brendensoares Why is it important to store the messagesPath ? After the message dictionary is built is there any need for the path to be stored ? Perhaps if I understood the usefulness of this it would make more sense.

@brendensoares
Copy link
Member

@AnonX @notzippy I'm thinking that we have a user configurable MessagesPath that is searched for message files. We may also have a single user configurable flag, such as SearchModulesForMessages, that would then adds all detected modules' path to MessagesPath.

"Separation of Concerns" seems like a good pattern to follow in general and this is an opportunity to use it. Agreed?

@brendensoares
Copy link
Member

Thanks @notzippy and @jeevatkm for feedback.

@brendensoares brendensoares merged commit 838106e into revel:develop May 27, 2016
jeevatkm added a commit that referenced this pull request May 27, 2016
@jeevatkm jeevatkm added the type-feature New feature request label Jun 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy