added missing modules for makepot task + added suport for plural forms in html templates + added all major i18n methods in twig

This commit is contained in:
Jonathan Labreuille
2015-07-29 19:15:21 +02:00
parent acc3854ba9
commit ec20abb1ee
868 changed files with 178636 additions and 71 deletions

View File

@@ -0,0 +1,104 @@
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var yaml = require('../lib/js-yaml');
// Let define a couple of classes...
function Point(x, y, z) {
this.klass = 'Point';
this.x = x;
this.y = y;
this.z = z;
}
function Space(height, width, points) {
if (points) {
if (!points.every(function (point) { return point instanceof Point; })) {
throw new Error('A non-Point inside a points array!');
}
}
this.klass = 'Space';
this.height = height;
this.width = width;
this.points = points;
}
// Let define YAML types to load and dump our Point/Space objects.
var pointYamlType = new yaml.Type('!point', {
// The information used to load a Point.
loader: {
kind: 'array', // It must be an array. (sequence in YAML)
resolver: function (object) {
// It must contain exactly tree elements.
if (3 === object.length) {
return new Point(object[0], object[1], object[2]);
// Otherwise, it is NOT a Point.
} else {
return yaml.NIL;
}
}
},
// The information used to dump a Point.
dumper: {
kind: 'object', // It must be an object but not an array.
instanceOf: Point, // Also, it must be an instance of Point class.
representer: function (point) {
// And it should be represented in YAML as three-element sequence.
return [ point.x, point.y, point.z ];
}
}
});
var spaceYamlType = new yaml.Type('!space', {
loader: {
kind: 'object', // 'object' here means 'mapping' in YAML.
resolver: function (object) {
return new Space(object.height, object.width, object.points);
}
},
dumper: {
kind: 'object',
instanceOf: Space
// The representer is omitted here. So, Space objects will be dumped as is.
// That is regular mapping with three key-value pairs but with !space tag.
}
});
// After our types are defined, it's time to join them into a schema.
var SPACE_SCHEMA = yaml.Schema.create([ spaceYamlType, pointYamlType ]);
// And read a document using that schema.
fs.readFile(path.join(__dirname, 'custom_types.yaml'), 'utf8', function (error, data) {
var loaded;
if (!error) {
loaded = yaml.load(data, { schema: SPACE_SCHEMA });
console.log(util.inspect(loaded, false, 20, true));
} else {
console.error(error.stack || error.message || String(error));
}
});
// There are some exports to play with this example interactively.
module.exports.Point = Point;
module.exports.Space = Space;
module.exports.pointYamlType = pointYamlType;
module.exports.spaceYamlType = spaceYamlType;
module.exports.SPACE_SCHEMA = SPACE_SCHEMA;

View File

@@ -0,0 +1,18 @@
subject: Custom types in JS-YAML
spaces:
- !space
height: 1000
width: 1000
points:
- !point [ 10, 43, 23 ]
- !point [ 165, 0, 50 ]
- !point [ 100, 100, 100 ]
- !space
height: 64
width: 128
points:
- !point [ 12, 43, 0 ]
- !point [ 1, 4, 90 ]
- !space {} # An empty space

View File

@@ -0,0 +1,31 @@
'use strict';
var yaml = require('../lib/js-yaml');
var object = require('./dumper.json');
console.log(yaml.dump(object, {
flowLevel: 3,
styles: {
'!!int' : 'hexadecimal',
'!!null' : 'camelcase'
}
}));
// Output:
//==============================================================================
// name: Wizzard
// level: 0x11
// sanity: Null
// inventory:
// - name: Hat
// features: [magic, pointed]
// traits: {}
// - name: Staff
// features: []
// traits: {damage: 0xA}
// - name: Cloak
// features: [old]
// traits: {defence: 0x0, comfort: 0x3}

View File

@@ -0,0 +1,22 @@
{
"name" : "Wizzard",
"level" : 17,
"sanity" : null,
"inventory" : [
{
"name" : "Hat",
"features" : [ "magic", "pointed" ],
"traits" : {}
},
{
"name" : "Staff",
"features" : [],
"traits" : { "damage" : 10 }
},
{
"name" : "Cloak",
"features" : [ "old" ],
"traits" : { "defence" : 0, "comfort" : 3 }
}
]
}

View File

@@ -0,0 +1,15 @@
'use strict';
var inspect = require('util').inspect;
// just require jsyaml
require('../lib/js-yaml');
try {
var doc = require(__dirname + '/sample_document.yaml');
console.log(inspect(doc, false, 10, true));
} catch (e) {
console.log(e.stack || e.toString());
}

View File

@@ -0,0 +1,197 @@
---
# Collection Types #############################################################
################################################################################
# http://yaml.org/type/map.html -----------------------------------------------#
map:
# Unordered set of key: value pairs.
Block style: !!map
Clark : Evans
Ingy : döt Net
Oren : Ben-Kiki
Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }
# http://yaml.org/type/omap.html ----------------------------------------------#
omap:
# Explicitly typed ordered map (dictionary).
Bestiary: !!omap
- aardvark: African pig-like ant eater. Ugly.
- anteater: South-American ant eater. Two species.
- anaconda: South-American constrictor snake. Scaly.
# Etc.
# Flow style
Numbers: !!omap [ one: 1, two: 2, three : 3 ]
# http://yaml.org/type/pairs.html ---------------------------------------------#
pairs:
# Explicitly typed pairs.
Block tasks: !!pairs
- meeting: with team.
- meeting: with boss.
- break: lunch.
- meeting: with client.
Flow tasks: !!pairs [ meeting: with team, meeting: with boss ]
# http://yaml.org/type/set.html -----------------------------------------------#
set:
# Explicitly typed set.
baseball players: !!set
? Mark McGwire
? Sammy Sosa
? Ken Griffey
# Flow style
baseball teams: !!set { Boston Red Sox, Detroit Tigers, New York Yankees }
# http://yaml.org/type/seq.html -----------------------------------------------#
seq:
# Ordered sequence of nodes
Block style: !!seq
- Mercury # Rotates - no light/dark sides.
- Venus # Deadliest. Aptly named.
- Earth # Mostly dirt.
- Mars # Seems empty.
- Jupiter # The king.
- Saturn # Pretty.
- Uranus # Where the sun hardly shines.
- Neptune # Boring. No rings.
- Pluto # You call this a planet?
Flow style: !!seq [ Mercury, Venus, Earth, Mars, # Rocks
Jupiter, Saturn, Uranus, Neptune, # Gas
Pluto ] # Overrated
# Scalar Types #################################################################
################################################################################
# http://yaml.org/type/binary.html --------------------------------------------#
binary:
canonical: !!binary "\
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
generic: !!binary |
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
description:
The binary value above is a tiny arrow encoded as a gif image.
# http://yaml.org/type/bool.html ----------------------------------------------#
bool:
- true
- True
- TRUE
- false
- False
- FALSE
# http://yaml.org/type/float.html ---------------------------------------------#
float:
canonical: 6.8523015e+5
exponentioal: 685.230_15e+03
fixed: 685_230.15
sexagesimal: 190:20:30.15
negative infinity: -.inf
not a number: .NaN
# http://yaml.org/type/int.html -----------------------------------------------#
int:
canonical: 685230
decimal: +685_230
octal: 02472256
hexadecimal: 0x_0A_74_AE
binary: 0b1010_0111_0100_1010_1110
sexagesimal: 190:20:30
# http://yaml.org/type/merge.html ---------------------------------------------#
merge:
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
# All the following maps are equal:
- # Explicit keys
x: 1
y: 2
r: 10
label: nothing
- # Merge one map
<< : *CENTER
r: 10
label: center
- # Merge multiple maps
<< : [ *CENTER, *BIG ]
label: center/big
- # Override
<< : [ *BIG, *LEFT, *SMALL ]
x: 1
label: big/left/small
# http://yaml.org/type/null.html ----------------------------------------------#
null:
# This mapping has four keys,
# one has a value.
empty:
canonical: ~
english: null
~: null key
# This sequence has five
# entries, two have values.
sparse:
- ~
- 2nd entry
-
- 4th entry
- Null
# http://yaml.org/type/str.html -----------------------------------------------#
string: abcd
# http://yaml.org/type/timestamp.html -----------------------------------------#
timestamp:
canonical: 2001-12-15T02:59:43.1Z
valid iso8601: 2001-12-14t21:59:43.10-05:00
space separated: 2001-12-14 21:59:43.10 -5
no time zone (Z): 2001-12-15 2:59:43.10
date (00:00:00Z): 2002-12-14
# JavaScript Specific Types ####################################################
################################################################################
# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp
regexp:
simple: !!js/regexp foobar
modifiers: !!js/regexp /foobar/mi
# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined
undefined: !!js/undefined ~
# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function
function: !!js/function >
function foobar() {
return 'Wow! JS-YAML Rocks!';
}