Skip to content

komkanit/tedxkaset

Repository files navigation

tedxkaset

Installation

  • using node v.6
  • run command npm install or yarn to install packages
  • add config to your .env file
COOKIE_SECRET=
CLOUDINARY_URL=
MANDRILL_API_KEY=
MONGO_URI=

Development

  • run command node keystone or yarn start to start project. TEDxKasetsartU website should open in http://localhost:3000.

App wide constants

Write your app wide constants in /constants.js for easy use across the app.

var consts = require('../constants.js');
console.log(consts.locales);

Internationalization (i18n)

There's couple of gotchas with the internationalization of TEDxKasetsartU website.

Configuration

Used locales and e.g. name of the cookie containing locale are stored in constants.js.

Static translations

Locale files are located in locales/. They're somewhat autogenerated so don't touch anything else than the translated string values.

.jade templates

Use __('view_id_here.string_id_here') for all hard coded strings. See templates/views/index.jade for further reference.

Example:

p
  | !{__('index.new_website', {keystoneLink: '<a href="http://keystonejs.com" target="_blank">KeystoneJS</a>'})}

Dynamic content translations

Creating and using translatable fields for dynamic content is possible with createField, combineFields and getField.

Models
var keystone = require('keystone');
const { createField, combineFields } = require('keystone-translated-fields');

const locales = require('../constants').locales;
const Types = keystone.Field.Types;

const Speaker = new keystone.List('Speaker', {
	map: {
		name: 'title',
	},
	singular: 'Speaker',
	plural: 'Speakers',
	autokey: {
		path: 'slug',
		from: 'title',
		unique: true,
	},
});

Speaker.add(combineFields([
	{ title: { type: String, required: true } },
	{ name: { type: String } },
	{ desc: { type: Types.Html, wysiwyg: true, height: 300 } },
	{ image: { type: Types.CloudinaryImage } },
	createField('about', { type: String }, locales),
]));

Speaker.register();
Templates
h3 #{getField(speaker, 'title', locale)}
if speaker.desc
	!= speaker.desc
p #{getField(speaker, 'about', locale)}

Contribution

Follow git flow.