Repository: ember-intl/ember-intl
Pull request #689 (2018-11-15 03:37:33)

chore: deprecate throwMissingTranslations to errorOnMissingTranslations
Related to discussion on #683


Patch:
diff --git a/blueprints/ember-intl/files/config/ember-intl.js b/blueprints/ember-intl/files/config/ember-intl.js
index 842fa67b..2604ac50 100644
--- a/blueprints/ember-intl/files/config/ember-intl.js
+++ b/blueprints/ember-intl/files/config/ember-intl.js
@@ -65,11 +65,11 @@ module.exports = function(/* env */) {
      *
      * See https://github.com/jasonmit/ember-intl/blob/master/docs/missing-translations.md#throwing-a-build-error-on-missing-required-translation
      *
-     * @property throwMissingTranslations
+     * @property errorOnMissingTranslations
      * @type {Boolean}
      * @default "false"
      */
-    throwMissingTranslations: false,
+    errorOnMissingTranslations: false,
 
     /**
      * filter missing translations to ignore expected missing translations.
diff --git a/config/ember-intl.js b/config/ember-intl.js
index d510f9dd..e3bac3b0 100644
--- a/config/ember-intl.js
+++ b/config/ember-intl.js
@@ -54,11 +54,11 @@ module.exports = function(/* environment */) {
      *
      * See https://github.com/jasonmit/ember-intl/blob/master/docs/missing-translations.md#throwing-a-build-error-on-missing-required-translation
      *
-     * @property throwMissingTranslations
+     * @property errorOnMissingTranslations
      * @type {Boolean}
      * @default "false"
      */
-    throwMissingTranslations: false,
+    errorOnMissingTranslations: false,
 
     /**
      * filter missing translations to ignore expected missing translations.
diff --git a/docs/missing-translations.md b/docs/missing-translations.md
index 0ffd4cf3..0e4e1cc2 100644
--- a/docs/missing-translations.md
+++ b/docs/missing-translations.md
@@ -23,7 +23,7 @@ The feature, and the documentation, is based entirely off ember-i18n's. The `opt
 
 Ember Intl automatically detects missing translations when building the app.
 
-You can control the detection behavior by configuring the `throwMissingTranslations` and `requiresTranslation` options in your `config/ember-intl.js`.
+You can control the detection behavior by configuring the `errorOnMissingTranslations` and `requiresTranslation` options in your `config/ember-intl.js`.
 
 ### Requiring translations
 
@@ -77,7 +77,7 @@ page:
 
 ### Throwing a build error on missing, required translation
 
-Setting `throwMissingTranslations` to `true` will cause ember-intl to throw a build error if missing, required translations were detected.
+Setting `errorOnMissingTranslations` to `true` will cause ember-intl to throw a build error if missing, required translations were detected.
 This changes the default behavior where missing translations are only logged as build warnings.
 
 Given the following configuration, any missing translation in any locale will cause a build error to be thrown.
@@ -86,7 +86,7 @@ Given the following configuration, any missing translation in any locale will ca
 // config/ember-intl.js
 module.exports = function(/* environment */) {
   return {
-    throwMissingTranslations: true,
+    errorOnMissingTranslations: true,
   };
 };
 ```
diff --git a/index.js b/index.js
index b47db47f..365f3c38 100644
--- a/index.js
+++ b/index.js
@@ -25,7 +25,7 @@ const defaultConfig = {
   autoPolyfill: false,
   inputPath: 'translations',
   outputPath: 'translations',
-  throwMissingTranslations: false,
+  errorOnMissingTranslations: false,
   requiresTranslation: (/* key, locale */) => true
 };
 
@@ -48,17 +48,23 @@ module.exports = {
     const _bundlerOptions = bundlerOptions || {};
     const addon = this;
 
+    if ('throwMissingTranslations' in this.opts) {
+      this.log('DEPRECIATION: `throwMissingTranslations` has been renamed to `errorOnMissingTranslations`', {
+        warning: true
+      });
+    }
+
     return new TranslationReducer(translationTree, {
       verbose: !this.isSilent,
       outputPath: this.opts.outputPath,
       filename: _bundlerOptions.filename,
       wrapEntry: _bundlerOptions.wrapEntry,
+      requiresTranslation: this.opts.requiresTranslation,
+      errorOnMissingTranslations: this.opts.throwMissingTranslations || this.opts.errorOnMissingTranslations,
+      stripEmptyTranslations: this.opts.stripEmptyTranslations,
       log() {
         return addon.log.apply(addon, arguments);
-      },
-      requiresTranslation: this.opts.requiresTranslation,
-      throwMissingTranslations: this.opts.throwMissingTranslations,
-      stripEmptyTranslations: this.opts.stripEmptyTranslations
+      }
     });
   },
 
diff --git a/lib/broccoli/translation-reducer.js b/lib/broccoli/translation-reducer.js
index 4282ef10..f84c3ebb 100644
--- a/lib/broccoli/translation-reducer.js
+++ b/lib/broccoli/translation-reducer.js
@@ -158,12 +158,12 @@ class TranslationReducer extends CachingWriter {
       if (
         this.options.verbose &&
         // log messages if not failing as it's duplicated console output
-        !this.options.throwMissingTranslations
+        !this.options.errorOnMissingTranslations
       ) {
         missingTranslationMessages.forEach(message => this._log(message));
       }
 
-      if (this.options.throwMissingTranslations) {
+      if (this.options.errorOnMissingTranslations) {
         throw new Error('Missing translations:\n' + missingTranslationMessages.map(text => `- ${text}`).join('\n'));
       }
     }


Test patch:
diff --git a/tests-node/unit/broccoli/translation-reducer-test.js b/tests-node/unit/broccoli/translation-reducer-test.js
index 2a6ea7d7..ab440358 100644
--- a/tests-node/unit/broccoli/translation-reducer-test.js
+++ b/tests-node/unit/broccoli/translation-reducer-test.js
@@ -68,10 +68,10 @@ describe('translation-reducer', function() {
     ]);
   });
 
-  it('handleMissingTranslations throws if throwMissingTranslations is set', function() {
+  it('handleMissingTranslations throws if errorOnMissingTranslations is set', function() {
     const logs = [];
     const reducer = new subject('src');
-    reducer.options.throwMissingTranslations = true;
+    reducer.options.errorOnMissingTranslations = true;
 
     reducer._log = msg => logs.push(msg);