This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from jamesarosen/james/legacy-tree
Include ember 1.12 support only on 1.12
- Loading branch information
Showing
12 changed files
with
122 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
import Ember from "ember"; | ||
|
||
var Helper = null; | ||
export default Ember.Helper.extend({ | ||
i18n: Ember.inject.service(), | ||
|
||
if (Ember.Helper) { | ||
Helper = Ember.Helper.extend({ | ||
i18n: Ember.inject.service(), | ||
_locale: Ember.computed.readOnly('i18n.locale'), | ||
|
||
_locale: Ember.computed.readOnly('i18n.locale'), | ||
compute: function(params, interpolations) { | ||
const key = params[0]; | ||
const i18n = this.get('i18n'); | ||
return i18n.t(key, interpolations); | ||
}, | ||
|
||
compute: function(params, interpolations) { | ||
const key = params[0]; | ||
const i18n = this.get('i18n'); | ||
return i18n.t(key, interpolations); | ||
}, | ||
|
||
_recomputeOnLocaleChange: Ember.observer('_locale', function() { | ||
this.recompute(); | ||
}) | ||
}); | ||
} | ||
|
||
export default Helper; | ||
_recomputeOnLocaleChange: Ember.observer('_locale', function() { | ||
this.recompute(); | ||
}) | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This folder includes support for Ember 1.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Stream from "./stream"; | ||
import { readHash } from "./stream"; | ||
|
||
export default function tHelper(params, hash, options, env) { | ||
const i18n = env.data.view.container.lookup('service:i18n'); | ||
const i18nKey = params[0]; | ||
|
||
var out = new Stream(function() { | ||
const value = i18nKey.isStream ? i18nKey.value() : i18nKey; | ||
return value === undefined ? '' : i18n.t(value, readHash(hash)); | ||
}); | ||
|
||
// Once the view is destroyed destroy the steam as well | ||
env.data.view.one('willDestroyElement', out, function() { | ||
this.destroy(); | ||
}); | ||
|
||
// observe any hash arguments that are streams: | ||
Object.keys(hash).forEach(function(key) { | ||
const value = hash[key]; | ||
|
||
if (value && value.isStream) { | ||
value.subscribe(out.notify, out); | ||
} | ||
}); | ||
|
||
// observe the locale: | ||
i18n.localeStream.subscribe(out.notify, out); | ||
|
||
// if the i18n key itself is dynamic, observe it: | ||
if (i18nKey.isStream) { | ||
i18nKey.subscribe(out.notify, out); | ||
} | ||
|
||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Ember from "ember"; | ||
import Stream from './stream'; | ||
import legacyHelper from "./helper"; | ||
|
||
// Used for Ember < 1.13 | ||
export default { | ||
name: 'ember-i18n-legacy-helper', | ||
|
||
initialize(registry) { | ||
const i18n = registry.lookup('service:i18n'); | ||
|
||
i18n.localeStream = new Stream(function() { | ||
return i18n.get('locale'); | ||
}); | ||
|
||
Ember.addObserver(i18n, 'locale', i18n, function() { | ||
this.localeStream.value(); // force the stream to be dirty | ||
this.localeStream.notify(); | ||
}); | ||
|
||
Ember.HTMLBars._registerHelper('t', legacyHelper); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Ember from 'ember'; | ||
|
||
// As of v1.12, Streams are still private API. Thus, we need to reach in to | ||
// Ember internals to get access to it. | ||
// | ||
// See https://github.com/emberjs/ember.js/blob/v1.12.0/packages/ember-metal/lib/main.js#L384-L386 | ||
// See https://github.com/emberjs/ember.js/pull/9693 | ||
// See https://github.com/dockyard/ember-cli-i18n/blob/v0.0.6/addon/utils/stream.js | ||
|
||
export default Ember.__loader.require('ember-metal/streams/stream')['default']; | ||
export const readHash = Ember.__loader.require('ember-metal/streams/utils').readHash; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import initializer from 'ember-i18n/legacy/initializer'; | ||
export default initializer; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,42 @@ | ||
/* jshint node: true */ | ||
'use strict'; | ||
var Funnel = require('broccoli-funnel'); | ||
var VersionChecker = require('ember-cli-version-checker'); | ||
|
||
module.exports = { | ||
name: 'ember-i18n', | ||
isLocalizationFramework: true, | ||
|
||
isLocalizationFramework: true | ||
config: function() { | ||
var checker = new VersionChecker(this); | ||
var dep = checker.for('ember', 'bower'); | ||
this.hasEmberHelper = !dep.lt('1.13.0'); | ||
return this._super.config.apply(this, arguments); | ||
}, | ||
|
||
treeFor: function(name) { | ||
var result = this._super.treeFor.apply(this, arguments); | ||
|
||
if (this.hasEmberHelper) { | ||
result = exclude(result, [ | ||
'initializers/ember-i18n-legacy-helper.js', | ||
'modules/ember-i18n/legacy/helper.js', | ||
'modules/ember-i18n/legacy/initializer.js', | ||
'modules/ember-i18n/legacy/stream.js' | ||
]); | ||
} else { | ||
result = exclude(result, [ | ||
'helpers/t.js', | ||
'modules/ember-i18n/helper.js' | ||
]); | ||
} | ||
|
||
return result; | ||
} | ||
}; | ||
|
||
function exclude(tree, files) { | ||
return new Funnel(tree, { | ||
exclude: files | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters