Skip to content

Commit

Permalink
i18n menu refactor, doc updates
Browse files Browse the repository at this point in the history
Populates language selections from shops.languages rather than the
translation files.
Remove “entryText” from translation files.
No need to provide core.languages in translation, selections are in
native format for all languages by default
(you can still override in translations though)
Publication no longer returns all translations, just EN + chosen
language

Adds some checks for publications for Issue #14
Documentation updates for Issue #245
Resolves #251
  • Loading branch information
aaronjudd committed Feb 19, 2015
1 parent c7c47c5 commit 2fc6592
Show file tree
Hide file tree
Showing 27 changed files with 361 additions and 508 deletions.
5 changes: 5 additions & 0 deletions packages/reaction-core/client/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ _.extend ReactionCore,
return @shopId

Meteor.startup ->
# todo: this could grow.. and grow...
# quick little client safety check
if (PackageRegistry?) then console.error "Bravely warning you that PackageRegistry should not be exported to client." if (!PackageRegistry?)

# Ignition.....
ReactionCore.init()
2 changes: 1 addition & 1 deletion packages/reaction-core/client/helpers/i18n/i18n.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Meteor.startup ->
Tracker.autorun () ->
sessionLanguage = Session.get "language"
Meteor.subscribe "Translations", sessionLanguage, () ->
resources = ReactionCore.Collections.Translations.find({ $or: [{'i18n':'en'},{'i18n': sessionLanguage}] },{fields:{_id: 0},reactive:false}).fetch()
resources = ReactionCore.Collections.Translations.find({},{fields:{_id: 0},reactive:false}).fetch()
# map multiple translations into i18next format
resources = resources.reduce (x, y) ->
x[y.i18n]= y.translation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Template.i18nChooser.helpers
languages: ->
return ReactionCore.Collections.Translations.find({},{fields:{'language':1, 'i18n': 1, 'entryText': 1}})
languages = []
shop = ReactionCore.Collections.Shops.findOne()
if shop?.languages
for language in shop.languages
if language.enabled is true
language.translation = "languages." + language.label.toLowercase
languages.push language
return languages

active: () ->
if Session.equals "language", @.i18n
Expand All @@ -9,4 +16,4 @@ Template.i18nChooser.helpers
Template.i18nChooser.events
'click .i18n-language': (event,template)->
event.preventDefault()
Session.set('language',@.i18n)
Session.set('language',@.i18n)
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<li role="presentation" class="dropdown-header" data-i18n="languages.select">Select Language</li>
<li class="divider"></li>
{{#each languages}}
<li class="{{active}}"><a href="#" role="menuitem" class="i18n-language">{{#if entryText }} {{entryText}} {{else}} {{language}} {{/if}}</a></li>
<li class="{{active}}"><a role="menuitem" class="i18n-language" data-i18n="{{translation}}">{{label}}</a></li>
{{/each}}
</ul>
</div>
</template>
</template>
26 changes: 16 additions & 10 deletions packages/reaction-core/docs/i18n.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Internationalization (i18n)
##i18n
##i18n
We use the [http://i18next.com/](http://i18next.com/) i18n library for translations.

- usage - inline tag: `<td data-i18n='cartSubTotals.items'>`
- usage - in template: `{{i18n 'cartDrawer.empty'}}`
- usage - data attribute: `<td data-i18n='cartSubTotals.items'>`
- usage - template helper: `{{i18n 'cartDrawer.empty'}}`
- usage - reference: `<thead data-i18n>cartSubTotals.head</thead>`
- usage - implied tag: `<td data-i18n>Item Count</td>`
- usage - alerts `Alerts.add "Message!", "danger", i18n_key: "productDetail.outOfStock"`
Expand All @@ -17,7 +17,7 @@ The fallback language is EN, so all new translations should go in `reaction-core
<thead data-i18n='cartSubTotals.head'>Your cart</thead>
```

This will first use "Your cart", then will fetch translations from the `Translations` collection. IE for English, will look in `en` for
This will first use "Your cart", then will fetch translations from the `Translations` collection. IE for English, will look in `en` for

```
{
Expand All @@ -30,14 +30,14 @@ This will first use "Your cart", then will fetch translations from the `Translat
If there is no entry in English dictionary, we'll just use the text value from the template.

## Pricing Localization
Currency formatting is determined by users locale currency.
Currency formatting is determined by users locale currency.
The currency formatting is stored in the `Shops.currencies` object, and the configuration data is available in the client as `ReactionCore.Locale`

We've created `formatPrice` and `currencySymbol` helpers for using in templates:

{{formatPrice price}}

We use the [accounting.js](http://openexchangerates.github.io/accounting.js/) library for formatting.
We use the [accounting.js](http://openexchangerates.github.io/accounting.js/) library for formatting.

Typical usage is `price = accounting.formatMoney price, ReactionCore.Locale.currency`

Expand All @@ -46,9 +46,15 @@ Initial translation data that gets loaded with a new shop is located in `private

Every package that supplies translations should add a fixture for translations that add their own namespace (ie: helloworld), and insert initial translations into the `translations` collection.

New languages will need to edit the languages array in `server/fixtures.coffee`
New languages will need to edit the languages array in the shops collection, or in the fixture data `reaction-core/private/data/Shops.json`. The `i18n` value should match file name in `private/data/i18n/*`.

languages = ["ar","cs","de","en","es","fr","he","it","my","pl","pt","ru","sl","sv","vi"]
TODO: *Each package should have its own namespaced translation files.*
```
"languages": [
{
"label": "العربية",
"i18n": "ar",
"enabled": true
}
]
```

154 changes: 81 additions & 73 deletions packages/reaction-core/docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#Installation
**Prerequisites: Install npm and [node.js](http://nodejs.org/)**

Once node (with `npm`) is installed, install meteor, clone the repo, and then start the application from the Terminal commmand line:
Ensure that node (with `npm`) is installed, and then install Meteor.
*Optional, but suggested: install `graphicsmagick`*.

Clone the `reactioncommerce/reaction` repo, and then start the application from the Terminal commmand line:

```bash
curl https://install.meteor.com | /bin/sh
git clone https://github.com/reactioncommerce/reaction.git
cd reaction
cd reaction && git checkout master
meteor
```

*Optional, but suggested: install `graphicsmagick`*
This is the `master` branch. This will ensure your initial installation is a stable release.

`git checkout development` to use the development branch. See [the package development documentation](https://github.com/reactioncommerce/reaction-core/blob/master/docs/packages.md) for details on working from the `development` branch.

##Startup
**Start**
To start Reaction, run the `meteor` command:

Browse to [http://localhost:3000](http://localhost:3000) and you should see Reaction running (sample data same as on demo site)
Expand All @@ -21,7 +26,7 @@ The initial admin user for the site is auto generated, and displayed in your con

*Note: If you are running Reaction remotely (not localhost, ie: vm, aws, docker, etc) and don't want https forwarding, you may remove the [Meteor force-ssl](https://atmospherejs.com/meteor/force-ssl) package using `meteor remove force-ssl`. See [section in docs regarding https](https://github.com/reactioncommerce/reaction-core/blob/master/docs/installation.md#https).*

## Reset
**Reset**
To reset project data and give you a fresh test dataset from `packages/reaction-core/private/data/*.json`:

meteor reset
Expand All @@ -40,101 +45,102 @@ meteor

*Note: currently we're not testing data schema compatibility between versions, which is why we use `meteor reset` in this example. It's not necessary if you want to preserve your data, but there may be compatibility issues.*

#Deploying
An example of a deployment with password to a [meteor.com hosted site](http://docs.meteor.com/#deploying) using config from settings/prod.json
##Meteor settings
A Meteor settings file can be used with the `meteor --settings` option.

meteor deploy --settings settings/prod.json yourdemosite.meteor.com
Copy [settings/dev.sample.json](https://github.com/reactioncommerce/reaction/blob/master/settings/dev.sample.json) and create a new `settings.json` file, for example:

*Note: If you are running Reaction remotely (not localhost, ie: vm, aws, docker, etc) and don't want https forwarding, you may remove the [Meteor force-ssl](https://atmospherejs.com/meteor/force-ssl) package using `meteor remove force-ssl`. See [section in docs regarding https](https://github.com/reactioncommerce/reaction-core/blob/master/docs/installation.md#https).*

```json
{
"ROOT_URL": "",
"MONGO_URL": "",
"MAIL_URL": "",
"reaction": {
"METEOR_USER": "<username>",
"METEOR_AUTH": "<password>",
"METEOR_EMAIL": "<login email>"
},
"isDebug": "info"
}
```

## settings.json configuration
A configuration file can be loaded using the `meteor --settings` option.
After you've created the `settings` file, add `--settings settings/settings.json` to the `meteor` startup command.

Copy [settings/dev.sample.json](https://github.com/reactioncommerce/reaction/blob/master/settings/dev.sample.json) and create a new configuration file, for example:
meteor --settings settings/settings.json --raw-logs

cd reaction
cp settings/dev.sample.json settings/settings.json
### Environment variables

After you've created and edited a configuration file, add `--settings settings/settings.json` to the `meteor` startup command.
You can also use environment variables for settings, useful for headless and automated vm configuration.

meteor --settings settings/settings.json --port 3000
```bash
export ROOT_URL=""
export MONGO_URL="<your mongodb connect string>"
export MAIL_URL="<smtp connection string>"

export METEOR_USER="<username>"
export METEOR_AUTH="<password>"
export METEOR_EMAIL="<login email>"
```

Example configuration file
The `METEOR_EMAIL`, `METEOR_USER`, `METEOR_AUTH` environment variables will configure the default administrator account.

```json
{
"baseUrl": "http://localhost:3000",
"googleAnalyticsProperty": "__KEY__",
"facebook": {
"secret": "__SECRET__"
},
"reaction": {
"METEOR_USER": "Administrator",
"METEOR_AUTH": "password",
"METEOR_EMAIL": "root@localhost"
},
"public": {
"isDebug": true,
"facebook": {
"appId": "__APP_ID__"
}
}
}
```
*Note: Environment variables will override variables set in settings.json*

### Environment variables
**ROOT_URL**

You can also use many of the settings as environment variables, useful for headless and automated vm configuration.
*Export `ROOT_URL` and `packages/reaction-core/fixtures.coffee` will update the domain in the `shops` collection to match the domain from `ROOT_URL`.* This lets you use alternate domains, or enforce SSL on a fresh installation. An empty ROOT_URL will just default to *localhost*.

```bash
export MAIL_URL="<smtp connection string>"
export METEOR_EMAIL="[email protected]"
export METEOR_USER="admin"
export METEOR_AUTH="password"
export MONGO_URL="<your mongodb connect string>"
export ROOT_URL=""
```
**MAIL_URL**
To send email you should configure the administrative SMTP email server. [env MAIL_URL variable](http://docs.meteor.com/#email_send)

Alternatively can also set environment variables by adding them to a settings.json file, like so:
*Note: This is not required, but password reset, and a few other items that use email templates won't work unless you configure this.*

```
"reaction": {
"METEOR_USER": "Administrator",
"METEOR_AUTH": "password",
"METEOR_EMAIL": "root@localhost"
}
```
**isDebug**
Sets debugging levels. Accepts `true`,`false` or logging level.

This can be useful (or even necessary) when deploying to a remote server that doesn't offer SSH access. *Note: Global environment variables will take precendence over variables set via settings.json*
See: [conventions#logging](https://github.com/reactioncommerce/reaction-core/blob/development/docs/conventions.md#logging).

The `METEOR_EMAIL`, `METEOR_USER`, `METEOR_AUTH` environment variables will create this email/user/password as the default first site admin user.
**These are the only `reaction specific` variables used from settings.json.**

To use another Mongodb, rather than the automatically instantiated development one:
##Fixture Data

```bash
export MONGO_URL=mongodb://localhost:27017/dbname
```
The `reaction-core` package installs sample data, translations, and other fixture defaults from `packages/reaction-core/private/data/`.

If you set ```ROOT_URL``` we'll automatically update the domain in the *shops* collection to match the domain from ROOT_URL. This lets you use alternate domains, or enforce SSL on your installation. An empty ROOT_URL will just default to *localhost*.
Each installed package ('Reaction App') can also provide fixture data.

See [the packages development documentation](https://github.com/reactioncommerce/reaction-core/blob/master/docs/packages.md) to modify this and other core packages locally.

### System Email
To send email you should configure the administrative SMTP email server. [env MAIL_URL variable](http://docs.meteor.com/#email_send)
A `server` method is available for loading collection fixture data:

*Note: This is not required, but password reset, and a few other items that use email templates won't work unless you configure this.*
*server/fixtures.coffee*
```
Meteor.startup ->
jsonFile = Assets.getText("private/data/Shipping.json")
Fixtures.loadData ReactionCore.Collections.Shipping, jsonFile
```

### HTTPS Redirect
You can use `meteor remove force-ssl` to remove redirection to the `https` protocol. To add back, `meteor add force-ssl`. When developing locally, you should not have to remove https as Meteor internally redirects all `localhost` requests to the `http` protocol. However, if you are running on a VM, or using Vagrant, you should run `meteor remove force-ssl` and remove this package locally.
##Troubleshooting

### Fixture data
The initial shop data is loaded from the reactioncommerce:reaction-core package /private/data directory. See [the packages development documentation](https://github.com/reactioncommerce/reaction-core/blob/master/docs/packages.md) to modify this and other core packages locally.
**HTTPS Redirect**
You can use `meteor remove force-ssl` to remove redirection to the `https` protocol. To add back, `meteor add force-ssl`. When developing locally, you should not have to remove https as Meteor internally redirects all `localhost` requests to the `http` protocol. However, if you are running on a VM, or using Vagrant, you should run `meteor remove force-ssl` and remove this package locally.

### Failed to load c++ Json message
**Failed to load c++ Json message**

You can ignore this error, but if it annoys you can run
```xcode-select --install``` (on a mac) or ```sudo apt-get install gcc make build-essential``` (on ubuntu)
`xcode-select --install` (on a mac) or
`sudo apt-get install gcc make build-essential` (on ubuntu)

**env: node: No such file or directory**
Caused by a broken node, npm installation.
Reinstall Node.js with NPM (or when packaged seperately, reinstall them both).

#Deploying
An example of a deployment with password to a [meteor.com hosted site](http://docs.meteor.com/#deploying)

meteor deploy --settings settings/<prod-settings>.json <yoursite>.meteor.com

*Note: If you are running Reaction remotely (not localhost, ie: vm, aws, docker, etc) and don't want https forwarding, you may remove the [Meteor force-ssl](https://atmospherejs.com/meteor/force-ssl) package using `meteor remove force-ssl`. See [section in docs regarding https](https://github.com/reactioncommerce/reaction-core/blob/master/docs/installation.md#https).*

##Docker
Requires installation of Docker. On OS X or Windows install [boot2docker](http://boot2docker.io/).
Expand All @@ -144,15 +150,17 @@ There is a Dockerfile in the project root that creates a Docker image of Reactio
We provide up to date images built from the master branch. These are the same images running on reactioncommerce.com. You can pull our latest build from the [Docker Hub](https://registry.hub.docker.com/u/ongoworks/reaction/), or from the Reaction directory you can build your own image:

```bash
docker build -t ongoworks/reaction .
docker build -t reactioncommerce/reaction-test.
```

Typically you would start a Docker/Reaction app container by starting the Docker image with the [docker command line `run`](https://docs.docker.com/reference/commandline/cli/#run):

```bash
docker run -i -t -e MONGO_URL="<your mongodb url>" -e ROOT_URL="http://localhost" -e PORT="8080" -p ::8080 -d ongoworks/reaction
docker run -p :8080 -it reactioncommerce/reaction-test
```

You can pass environment variables to Docker using `-e`, so to pass `ROOT_URL` you would do add `-e ROOT_URL="<myhost>"` to `docker run`.

*Note: you cannot yet deploy your local docker build to reactioncommerce.com, but this functionality is being developed in the Launchdock project at [launchdock.io](http://launchdock.io/)*


Expand Down
27 changes: 14 additions & 13 deletions packages/reaction-core/docs/vagrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ This example will allow you to access the Reaction/Meteor server on port localho

#Ubuntu

sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs curl git
sudo npm install -g meteorite
git clone https://github.com/ongoworks/reaction.git
cd reaction
mrt update


cp /home/vagrant/reaction/bin/../settings/dev.sample.json /home/vagrant/reaction/bin/../settings/dev.json
sudo ./bin/run
```bash
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs curl git imagemagick

curl https://install.meteor.com/ | sh
git clone https://github.com/reactioncommerce/reaction.git
cd reaction
meteor
```



Loading

0 comments on commit 2fc6592

Please sign in to comment.