From 09545d23d2fe8123fc96572ddac348ea1dc6390c Mon Sep 17 00:00:00 2001 From: phaux Date: Thu, 13 Feb 2020 16:36:31 +0100 Subject: [PATCH] Fixed legacy translations not working. --- src/translation-service.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/translation-service.js b/src/translation-service.js index a793fdd..295037b 100644 --- a/src/translation-service.js +++ b/src/translation-service.js @@ -72,7 +72,7 @@ function getMessage( language, msgCtx, msgId ) { const localeData = window.CKEDITOR_TRANSLATIONS[ language ]; if ( localeData != null ) { let key = String( msgId ).toLowerCase(); - if ( msgCtx !== null ) { + if ( msgCtx != null ) { key = `${ String( msgCtx ).toLowerCase() }|${ key }`; } @@ -80,6 +80,16 @@ function getMessage( language, msgCtx, msgId ) { if ( message != null ) { return message; } + + // Fall back to the old behavior where context was not used + if ( msgCtx == null ) { + for ( const localeKey in localeData ) { + const localeKeyMatch = localeKey.match( /^(.+)\|(.+)$/ ); + if ( localeKeyMatch != null && localeKeyMatch[ 2 ] == key ) { + return localeData[ localeKey ]; + } + } + } } return null;