Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarerero committed Aug 31, 2017
2 parents 638508f + fab1763 commit 271188b
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ When using `npm` the translation files will not be loaded eagerly any longer. Se

To make it work with `npm` the files have been translated to JavaScript, so if you use CoffeeScript you can require from the main directory and if you use JavaScript you would import/require from `build`.

Breaking change: Reactivity for the language and translations are no longer available. This used a Meteor functionality which is not available in a plain Node environment, which also consumed a lot of resources and many applications never used it. If this is a critical feature for somebody please open a ticket, this could be maybe implemented in a separate package.
In theory this package can be used in any JavaScript project, but reactivity is only available within a Meteor environment.

The `examples` show different use cases:
These `examples` show different use cases:

- meteorPackage: This is way it has been used in former versions as a meteor package.
- meteorNpm: Use t9n as npm package within Meteor.
Expand Down
41 changes: 34 additions & 7 deletions build/t9n.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/meteorNpm/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</body>

<template name="app">
Lang: {{currentLang}}
<h1>{{t9n 'hello' name='Meteor'}}</h1>
<h3>Lang: {{currentLang}}</h3>
{{t9n 'pun' subject='Fischer\'s Fritz' predicate='fischt' object='Fische' adverb='frische'}}
<br/>
<br/>
Expand Down
8 changes: 7 additions & 1 deletion examples/meteorNpm/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ T9n.map('de', {
'hello': 'Hallo @{name}!',
'pun': '@{subject} @{predicate} @{adverb} @{object}. Frische @{object} @{predicate} @{subject}.',
});
T9n.map('es', {
'hello': 'Hola @{name}!',
'pun': 'No anda bien en castellano eso de "@{subject} @{predicate} @{adverb} @{object}. Frische @{object} @{predicate} @{subject}".',
});
T9n.setLanguage('de');

// as the template helper is not registered at this moment do it here
Template.registerHelper('t9n', (x, params) => T9n.get(x, true, params.hash));
Template.registerHelper('currentLang', () => T9n.getLanguage());

Template.app.events({
'click button': () => T9n.setLanguage('es'), // no reactivity!
'click button': () => T9n.setLanguage(flipLanguage()),
});

const flipLanguage = () => T9n.getLanguage() === 'es' ? 'de' : 'es';
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions examples/meteorPackage/client/client.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
lang = 'de'
T9n.setLanguage(lang)
T9n.map lang, 'hello': 'Hallo @{name}!'
T9n.map lang, 'pun': '@{subject} @{predicate} @{adverb} @{object}. Frische @{object} @{predicate} @{subject}.'
T9n.map 'es', 'hello': 'Hola @{name}!'

Template.registerHelper 'currentLang', () => T9n.getLanguage()

Template.app.events
'click button': => T9n.setLanguage flipLanguage()


flipLanguage = => if T9n.getLanguage() is 'es' then 'de' else 'es'
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
</head>

<body>
{{> app}}
</body>

<template name="app">
<h1>{{t9n 'hello' name='Meteor'}}</h1>
<h3>Lang: {{currentLang}}</h3>
{{t9n 'pun' subject='Fischer\'s Fritz' predicate='fischt' object='Fische' adverb='frische'}}
</body>
<br/>
<br/>
<button>{{t9n 'emailResetLink'}}</button>
</template>
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions examples/meteorPpackage/client/client.coffee

This file was deleted.

8 changes: 4 additions & 4 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
summary: "Almost i18n, with standard translations for basic meteor packages.",
version: "2.0.0-beta.2",
version: "2.0.0",
name: "softwarerero:accounts-t9n",
git: "https://github.com/softwarerero/meteor-accounts-t9n.git",
});
Expand All @@ -19,14 +19,14 @@ for (var i = 0; i < LANGUAGES.length; i++) {

Package.on_use(function (api, where) {
if (api.versionsFrom)
api.versionsFrom("METEOR@1.0.1");
api.versionsFrom("METEOR@1.1");
api.add_files(FILES, ['client', 'server']);
api.use(['coffeescript', 'deps'], ['client', 'server']);
api.use(['coffeescript', 'tracker'], ['client', 'server']);
api.export('T9n', ['client', 'server']);
});


Package.on_test(function (api) {
api.add_files(FILES, ['client', 'server']);
api.use(['coffeescript', 'deps'], ['client', 'server']);
api.use(['coffeescript', 'tracker'], ['client', 'server']);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meteor-accounts-t9n",
"version": "2.0.0-beta.2",
"version": "2.0.0",
"description": "Translations for Meteor projects, almost i18n",
"repository": "https://github.com/softwarerero/meteor-accounts-t9n",
"bugs": "https://github.com/softwarerero/meteor-accounts-t9n/issues",
Expand Down
2 changes: 1 addition & 1 deletion smart.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Translations for the meteor account's error messages",
"homepage": "https://github.com/softwarerero/meteor-accounts-t9n",
"author": "Stefan Undorf <el@softwarerero.com>",
"version": "1.3.11",
"version": "2.0.0",
"git": "https://github.com/softwarerero/meteor-accounts-t9n.git",
"packages": {}
}
13 changes: 13 additions & 0 deletions t9n.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tracker = require 'meteor/tracker'

Meteor?.startup ->
if Meteor.isClient
Template?.registerHelper 't9n', (x, params) ->
Expand All @@ -7,15 +9,21 @@ class T9n
@maps: {}
@defaultLanguage: 'en'
@language: ''
@dep: new tracker.Tracker.Dependency() if tracker.Tracker
@depLanguage: new tracker.Tracker.Dependency() if tracker.Tracker

@missingPrefix = ">"
@missingPostfix = "<"

@map: (language, map) ->
if(!@maps[language])
@maps[language] = {}
@registerMap(language, '', false, map)
@dep?.changed()

@get: (label, markIfMissing = true, args = {}, language) ->
@dep?.depend()
@depLanguage?.depend()
if typeof label != 'string' then return ''
language ?= @language
ret = @maps[language]?[label]
Expand All @@ -41,12 +49,15 @@ class T9n
@registerMap(language, prefix + key, true, value)

@getLanguage: () ->
@depLanguage?.depend()
return @language

@getLanguages: () ->
@dep?.depend()
return Object.keys(@maps).sort()

@getLanguageInfo: () ->
@dep?.depend()
keys = Object.keys(@maps).sort()
for k in keys
{name: @maps[k]['t9Name'], code: k}
Expand All @@ -60,6 +71,8 @@ class T9n
else
throw Error "language #{language} does not exist"
@language = language
@depLanguage?.changed()


@replaceParams = (str, args) ->
for key, value of args
Expand Down

0 comments on commit 271188b

Please sign in to comment.