8
0
Просмотр исходного кода

Created a Locale#language getter for backward compatibility after recent API changes. See ckeditor/ckeditor5-utils#296.

Aleksander Nowodzinski 6 лет назад
Родитель
Сommit
293377292f
2 измененных файлов с 44 добавлено и 0 удалено
  1. 26 0
      packages/ckeditor5-utils/src/locale.js
  2. 18 0
      packages/ckeditor5-utils/tests/locale.js

+ 26 - 0
packages/ckeditor5-utils/src/locale.js

@@ -7,6 +7,8 @@
  * @module utils/locale
  * @module utils/locale
  */
  */
 
 
+/* globals console */
+
 import { translate } from './translation-service';
 import { translate } from './translation-service';
 
 
 const RTL_LANGUAGE_CODES = [ 'ar', 'fa', 'he', 'ku', 'ug' ];
 const RTL_LANGUAGE_CODES = [ 'ar', 'fa', 'he', 'ku', 'ug' ];
@@ -95,6 +97,30 @@ export default class Locale {
 		this.t = ( ...args ) => this._t( ...args );
 		this.t = ( ...args ) => this._t( ...args );
 	}
 	}
 
 
+	/**
+	 * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
+	 *
+	 * **Note**: This property has been deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
+	 * properties instead.
+	 *
+	 * @deprecated
+	 * @member {String}
+	 */
+	get language() {
+		/**
+		 * The {@link module:utils/locale~Locale#language `Locale#language`} property has been deprecated and will
+		 * be removed in the near future. Please use {@link #uiLanguage} and {@link #contentLanguage} properties instead.
+		 *
+		 * @error locale-deprecated-language-property
+		 */
+		console.warn(
+			'locale-deprecated-language-property: ' +
+			'The Locale#language property has been deprecated and will be removed in the near future. ' +
+			'Please use #uiLanguage and #contentLanguage properties instead.' );
+
+		return this.uiLanguage;
+	}
+
 	/**
 	/**
 	 * Base for the {@link #t} method.
 	 * Base for the {@link #t} method.
 	 *
 	 *

+ 18 - 0
packages/ckeditor5-utils/tests/locale.js

@@ -3,11 +3,16 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
  */
 
 
+/* globals console */
+
 import Locale from '../src/locale';
 import Locale from '../src/locale';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 
 describe( 'Locale', () => {
 describe( 'Locale', () => {
 	let locale;
 	let locale;
 
 
+	testUtils.createSinonSandbox();
+
 	beforeEach( () => {
 	beforeEach( () => {
 		locale = new Locale();
 		locale = new Locale();
 	} );
 	} );
@@ -141,4 +146,17 @@ describe( 'Locale', () => {
 			expect( t( '%1 - %0 - %2', [ 'a' ] ) ).to.equal( '%1 - a - %2' );
 			expect( t( '%1 - %0 - %2', [ 'a' ] ) ).to.equal( '%1 - a - %2' );
 		} );
 		} );
 	} );
 	} );
+
+	describe( 'language()', () => {
+		it( 'should return #uiLanguage', () => {
+			expect( locale.language ).to.equal( locale.uiLanguage );
+		} );
+
+		it( 'should warn about deprecation', () => {
+			const stub = testUtils.sinon.stub( console, 'warn' );
+
+			expect( locale.language ).to.equal( 'en' );
+			sinon.assert.calledWithMatch( stub, 'locale-deprecated-language-property' );
+		} );
+	} );
 } );
 } );