Skip to content

Commit

Permalink
Merge branch 'ember-intl'
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer committed Jul 4, 2021
2 parents 83ce5fe + d9ed285 commit 6dfcc16
Show file tree
Hide file tree
Showing 145 changed files with 2,211 additions and 2,111 deletions.
2 changes: 1 addition & 1 deletion build/tasks/webpack/configurators/ember/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = function( config, grunt, isProd ) {
}
} ],
[ "babel-plugin-ember-modules-api-polyfill", {
blacklist: {
ignore: {
"@ember/debug": [ "assert", "deprecate", "warn" ]
}
} ],
Expand Down
2 changes: 1 addition & 1 deletion build/tasks/webpack/configurators/ember/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function( config, grunt, isProd ) {
}
} ],
[ "babel-plugin-ember-modules-api-polyfill", {
blacklist: {
ignore: {
"@ember/debug": [ "assert", "deprecate", "warn" ]
}
} ]
Expand Down
56 changes: 42 additions & 14 deletions build/tasks/webpack/configurators/ember/i18n.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
const { resolve: r } = require( "path" );
const { pRoot } = require( "../../paths" );

const webpack = require( "webpack" );
const { pDependencies, pLocales } = require( "../../paths" );
const { buildBabelConfig } = require( "../../utils" );


module.exports = function( config ) {
Object.assign( config.resolve.alias, {
"ember-i18n$": r( pRoot, "web_modules", "ember-i18n" )
});

// YAML loader (used by EmberI18n)
// translations
config.module.rules.push({
test: /\.ya?ml$/,
include: pLocales,
use: [
"optimized-json-loader",
"yaml-loader"
]
});

config.plugins.push(
// replace ember-i18n's get-locales utility function with a custom module
new webpack.NormalModuleReplacementPlugin(
/ember-i18n[\/\\]addon[\/\\]utils[\/\\]get-locales\.js$/,
r( pRoot, "web_modules", "ember-i18n", "get-locales.js" )
)
);
Object.assign( config.resolve.alias, {
"ember-intl": r( pDependencies, "ember-intl", "addon" )
});

config.module.rules.push({
test: /\.ts$/,
include: r( pDependencies, "ember-intl" ),
loader: "babel-loader",
options: buildBabelConfig({
plugins: [
[ "babel-plugin-debug-macros", {
flags: [
{
source: "@glimmer/env",
flags: {
DEBUG: false,
CI: false
}
}
],
externalizeHelpers: {
global: "Ember"
},
debugTools: {
isDebug: false,
source: "@ember/debug",
assertPredicateIndex: 1
}
} ],
[ "babel-plugin-ember-modules-api-polyfill", {
ignore: {
"@ember/debug": [ "assert", "deprecate", "warn" ]
}
} ],
"@babel/plugin-transform-typescript"
]
})
});
};
2 changes: 1 addition & 1 deletion build/tasks/webpack/configurators/ember/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = function( config ) {
}
} ],
[ "babel-plugin-ember-modules-api-polyfill", {
blacklist: {
ignore: {
"@ember/debug": [ "assert", "deprecate", "warn" ]
}
} ]
Expand Down
1 change: 0 additions & 1 deletion build/tasks/webpack/configurators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = [
require( "./code-quality" ),
require( "./nwjs" ),
require( "./ember" ),
require( "./moment" ),
require( "./app" ),
require( "./stylesheets-and-assets" ),
require( "./dev" ),
Expand Down
23 changes: 0 additions & 23 deletions build/tasks/webpack/configurators/moment.js

This file was deleted.

41 changes: 6 additions & 35 deletions build/tasks/webpack/plugins/i18n-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ module.exports = class WebpackI18nCoveragePlugin {
&& callee.property.type === "Identifier"
&& callee.property.name === "t"
&& (
// i18n.t( "key" )
// intl.t( "key" )
callee.object.type === "Identifier"
&& callee.object.name === "i18n"
// this.i18n.t( "key" )
&& callee.object.name === "intl"
// this.intl.t( "key" )
|| callee.object.type === "MemberExpression"
&& callee.object.object.type === "ThisExpression"
&& callee.object.property.type === "Identifier"
&& callee.object.property.name === "i18n"
// Ember.get( this, "i18n" ).t( "key" )
&& callee.object.property.name === "intl"
// Ember.get( this, "intl" ).t( "key" )
|| callee.object.type === "CallExpression"
&& callee.object.callee.type === "MemberExpression"
&& callee.object.callee.object.type === "Identifier"
Expand All @@ -204,30 +204,12 @@ module.exports = class WebpackI18nCoveragePlugin {
&& callee.object.arguments.length === 2
&& callee.object.arguments[0].type === "ThisExpression"
&& callee.object.arguments[1].type === "StringLiteral"
&& callee.object.arguments[1].value === "i18n"
&& callee.object.arguments[1].value === "intl"
)
) {
translationKey = args[0].value;
}

// pluralization via magic "count" parameter
// t( "key", { count } )
// t( "key", { count: value } )
if (
translationKey
&& args.length === 2
&& args[1].type === "ObjectExpression"
&& args[1].properties.some( ({ type, key, computed, method }) =>
type === "ObjectProperty"
&& !computed
&& !method
&& key.type === "Identifier"
&& key.name === "count"
)
) {
translationKey = `${translationKey}.*`;
}

if ( translationKey ) {
this.translationKeys.add( translationKey );
}
Expand Down Expand Up @@ -284,17 +266,6 @@ module.exports = class WebpackI18nCoveragePlugin {
.join( "" );
}

// pluralization via magic "count" parameter
// {{t "foo" count=value}}
if (
translationKey
&& hash
&& hash.type === "Hash"
&& hash.pairs.some( ({ type, key }) => type === "HashPair" && key === "count" )
) {
translationKey = `${translationKey}.*`;
}

if ( translationKey ) {
this.translationKeys.add( translationKey );
}
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ember-data": "3.9.0",
"ember-data-model-fragments": "4.0.0",
"ember-fetch": "6.5.0",
"ember-i18n": "5.2.0",
"ember-intl": "5.7.0",
"ember-inflector": "3.0.0",
"ember-localstorage-adapter": "github:bastimeyer/ember-localstorage-adapter#update-ember-latest",
"entities": "1.1.2",
Expand All @@ -27,7 +27,6 @@
"global-tld-list": "0.0.372",
"growly": "1.3.0",
"minimist": "1.2.5",
"moment": "2.21.0",
"punycode": "2.1.1",
"roboto-fontface": "0.8.0",
"semver": "5.5.0",
Expand All @@ -46,7 +45,7 @@
"@glimmer/syntax": "0.47.4",
"babel-loader": "8.2.2",
"babel-plugin-debug-macros": "0.2.0",
"babel-plugin-ember-modules-api-polyfill": "2.6.0",
"babel-plugin-ember-modules-api-polyfill": "3.5.0",
"babel-plugin-feature-flags": "0.3.1",
"babel-plugin-filter-imports": "2.0.4",
"babel-plugin-istanbul": "6.0.0",
Expand Down Expand Up @@ -92,15 +91,19 @@
"yaml-loader": "0.6.0"
},
"resolutions": {
"**/broccoli-caching-writer": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-concat": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-debug": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-file-creator": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-merge-files": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-merge-trees": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-plugin": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-rollup": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-funnel": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-source": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-stew": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/broccoli-templater": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/ember-auto-import": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/ember-cli-babel": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/ember-cli-babel-plugin-helpers": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
"**/ember-cli-get-component-path-option": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.0.tgz",
Expand Down
17 changes: 6 additions & 11 deletions src/app/data/models/twitch/channel/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const reLang = /^([a-z]{2})(:?-([a-z]{2}))?$/;


export default Model.extend({
i18n: service(),
/** @type {IntlService} */
intl: service(),
settings: service(),


Expand Down Expand Up @@ -60,18 +61,12 @@ export default Model.extend({
),


titleFollowers: computed( "i18n.locale", "followers", function() {
const i18n = get( this, "i18n" );
const count = get( this, "followers" );

return i18n.t( "models.twitch.channel.followers", { count } );
titleFollowers: computed( "intl.locale", "followers", function() {
return this.intl.t( "models.twitch.channel.followers", { count: this.followers } );
}),

titleViews: computed( "i18n.locale", "views", function() {
const i18n = get( this, "i18n" );
const count = get( this, "views" );

return i18n.t( "models.twitch.channel.views", { count } );
titleViews: computed( "intl.locale", "views", function() {
return this.intl.t( "models.twitch.channel.views", { count: this.views } );
}),


Expand Down
29 changes: 12 additions & 17 deletions src/app/data/models/twitch/stream/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { inject as service } from "@ember/service";
import attr from "ember-data/attr";
import Model from "ember-data/model";
import { belongsTo } from "ember-data/relationships";
import Moment from "moment";
import { DEFAULT_VODCAST_REGEXP } from "data/models/settings/streams/fragment";


Expand Down Expand Up @@ -39,7 +38,8 @@ const reRerun = /rerun|watch_party/;


export default Model.extend({
i18n: service(),
/** @type {IntlService} */
intl: service(),
settings: service(),


Expand All @@ -56,8 +56,8 @@ export default Model.extend({
viewers: attr( "number" ),


reVodcast: computed( "settings.streams.vodcast_regexp", function() {
const vodcast_regexp = get( this, "settings.streams.vodcast_regexp" );
reVodcast: computed( "settings.content.streams.vodcast_regexp", function() {
const vodcast_regexp = get( this, "settings.content.streams.vodcast_regexp" );
if ( vodcast_regexp.length && !vodcast_regexp.trim().length ) {
return null;
}
Expand Down Expand Up @@ -95,21 +95,16 @@ export default Model.extend({
hasFormatInfo: and( "video_height", "average_fps" ),


titleCreatedAt: computed( "i18n.locale", "created_at", function() {
const moment = new Moment( this.created_at );
const last24h = moment.diff( new Date(), "days" ) === 0;
const format = last24h
? this.i18n.t( "models.twitch.stream.created-at.less-than-24h" )
: this.i18n.t( "models.twitch.stream.created-at.more-than-24h" );

return moment.format( format.toString() );
titleCreatedAt: computed( "intl.locale", "created_at", function() {
const { created_at } = this;
const last24h = new Date() - created_at < 24 * 3600 * 1000;
return last24h
? this.intl.t( "models.twitch.stream.created-at.less-than-24h", { created_at } )
: this.intl.t( "models.twitch.stream.created-at.more-than-24h", { created_at } );
}),

titleViewers: computed( "i18n.locale", "viewers", function() {
const i18n = get( this, "i18n" );
const count = get( this, "viewers" );

return i18n.t( "models.twitch.stream.viewers", { count } );
titleViewers: computed( "intl.locale", "viewers", function() {
return this.intl.t( "models.twitch.stream.viewers", { count: this.viewers } );
}),

resolution: computed( "video_height", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/init/initializers/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {

initialize( application ) {
const ENV = {
i18n: {
intl: {
defaultLocale,
defaultFallback: defaultLocale
}
Expand Down
Loading

0 comments on commit 6dfcc16

Please sign in to comment.