@@ -27,65 +27,80 @@ import * as path from 'path';
2727import * as vscode from 'vscode' ;
2828
2929import { extensions , window } from 'vscode' ;
30+ import { l10n } from '../../../../localiser'
3031import { DEFAULT_BUNDLE_FILE_NAME , DEFAULT_PACKAGE_FILE_NAME , EXTENSION_NAME , SUPPORTED_LANGUAGES } from '../../constants' ;
3132import { checkCommandsLocalisation , checkConfigurationLocalisation , checkDebuggersLocalisation , checkL10nUsageInFiles , checkViewsLocalisation , getKeysFromJSON , matchKeys , matchValuesTemplate } from '../../testutils' ;
3233
3334
3435suite ( "Extension localisation tests" , function ( ) {
35- window . showInformationMessage ( "Starting Localisation tests" ) ;
36- // Check the consistency of the keys and value templates across the bundle files for the supported languages
37- test ( "Consistency of keys across bundle.l10n.lang.json files for supported languages" , async ( ) => {
38- const extension = extensions . getExtension ( EXTENSION_NAME ) ;
39- assert ( extension ) ;
40- const enBundlePath = path . join ( extension . extensionPath , "l10n" , DEFAULT_BUNDLE_FILE_NAME ) ;
41- assert . ok ( fs . existsSync ( enBundlePath ) , `${ DEFAULT_BUNDLE_FILE_NAME } doesn't exists` ) ;
42- for ( const lang of SUPPORTED_LANGUAGES ) {
43- const langBundlePath = path . join ( extension . extensionPath , "l10n" , `bundle.l10n.${ lang } .json` ) ;
44- assert . ok ( fs . existsSync ( langBundlePath ) , `bundle.l10n.${ lang } .json doesn't exists` ) ;
45- assert . ok ( matchKeys ( enBundlePath , langBundlePath ) , `Keys of ${ DEFAULT_BUNDLE_FILE_NAME } and bundle.l10n.${ lang } .json don't match` ) ;
46- assert . ok ( matchValuesTemplate ( enBundlePath , langBundlePath ) , `Value templates don't match for of the keys of ${ DEFAULT_BUNDLE_FILE_NAME } and bundle.l10n.${ lang } .json ` ) ;
47- }
48- } ) ;
36+ var lang = vscode . env . language ;
37+ const val = l10n . value ( "jdk.extension.runConfig.default.label" ) ;
38+ window . showInformationMessage ( "Starting Localisation tests" ) ;
39+ test ( "locale tests" , async ( ) => {
40+ assert . equal (
41+ l10n . value ( "jdk.downloader.message.downloadCompleted" , { "jdkVersion" :"25" , "osType" :"macOS" , "jdkType" :"OpenJDK" } ) ,
42+ "OpenJDK 25 for macOS download completed!"
43+ )
44+ assert . equal (
45+ l10n . value ( "jdk.downloader.error_message.installationCleanup" ) ,
46+ "Error while installation cleanup"
47+ )
48+ } )
4949
50- test ( "Consistency of keys across package.nls.lang.json files for supported languages" , async ( ) => {
51- const extension = extensions . getExtension ( EXTENSION_NAME ) ;
52- assert ( extension ) ;
53- const enPackagePath = path . join ( extension . extensionPath , DEFAULT_PACKAGE_FILE_NAME ) ;
54- assert . ok ( fs . existsSync ( enPackagePath ) , `${ DEFAULT_PACKAGE_FILE_NAME } doesn't exists` ) ;
55- for ( const lang of SUPPORTED_LANGUAGES ) {
56- const langPackagePath = path . join ( extension . extensionPath , `package.nls.${ lang } .json` ) ;
57- assert . ok ( fs . existsSync ( langPackagePath ) , `package.nls.${ lang } .json doesn't exists` ) ;
58- assert . ok ( matchKeys ( enPackagePath , langPackagePath ) , `Keys of ${ DEFAULT_PACKAGE_FILE_NAME } and package.nls.${ lang } .json don't match` ) ;
59- }
60- } ) ;
50+ window . showInformationMessage ( "Starting Localisation tests" ) ;
51+ // Check the consistency of the keys and value templates across the bundle files for the supported languages
52+ test ( "Consistency of keys across bundle.l10n.lang.json files for supported languages" , async ( ) => {
53+ const extension = extensions . getExtension ( EXTENSION_NAME ) ;
54+ assert ( extension ) ;
55+ const enBundlePath = path . join ( extension . extensionPath , "l10n" , DEFAULT_BUNDLE_FILE_NAME ) ;
56+ assert . ok ( fs . existsSync ( enBundlePath ) , `${ DEFAULT_BUNDLE_FILE_NAME } doesn't exists` ) ;
57+ for ( const lang of SUPPORTED_LANGUAGES ) {
58+ const langBundlePath = path . join ( extension . extensionPath , "l10n" , `bundle.l10n.${ lang } .json` ) ;
59+ assert . ok ( fs . existsSync ( langBundlePath ) , `bundle.l10n.${ lang } .json doesn't exists` ) ;
60+ assert . ok ( matchKeys ( enBundlePath , langBundlePath ) , `Keys of ${ DEFAULT_BUNDLE_FILE_NAME } and bundle.l10n.${ lang } .json don't match` ) ;
61+ assert . ok ( matchValuesTemplate ( enBundlePath , langBundlePath ) , `Value templates don't match for of the keys of ${ DEFAULT_BUNDLE_FILE_NAME } and bundle.l10n.${ lang } .json ` ) ;
62+ }
63+ } ) ;
6164
62- // Check localisable fields being appropriately localised for the contributes defined in package.json
63- test ( "Localisable fields in package.json localised properly " , async ( ) => {
64- const extension = extensions . getExtension ( EXTENSION_NAME ) ;
65- assert ( extension ) ;
66- const packagePath = path . join ( extension . extensionPath , "package.json" ) ;
67- assert . ok ( fs . existsSync ( packagePath ) , "package.json doesn't exists" ) ;
68- const enPackagePath = path . join ( extension . extensionPath , DEFAULT_PACKAGE_FILE_NAME ) ;
69- assert . ok ( fs . existsSync ( enPackagePath ) , `${ DEFAULT_PACKAGE_FILE_NAME } doesn't exists` ) ;
70- const validKeys : Set < string > = getKeysFromJSON ( enPackagePath ) ;
71- const packageObj = JSON . parse ( fs . readFileSync ( packagePath , 'utf8' ) ) ;
72- const contributes = packageObj . contributes
73- assert . ok ( checkCommandsLocalisation ( contributes . commands , validKeys ) , "Error some commands not localized" ) ;
74- assert . ok ( checkViewsLocalisation ( contributes . views , validKeys ) , "Error some views is not localized" ) ;
75- assert . ok ( checkDebuggersLocalisation ( contributes . debuggers , validKeys ) , "Error some debugger labels not localized" ) ;
76- assert . ok ( checkConfigurationLocalisation ( contributes . configuration , validKeys ) , "Error some configuration labels not localized" ) ;
77- } ) ;
65+ test ( "Consistency of keys across package.nls.lang.json files for supported languages" , async ( ) => {
66+ const extension = extensions . getExtension ( EXTENSION_NAME ) ;
67+ assert ( extension ) ;
68+ const enPackagePath = path . join ( extension . extensionPath , DEFAULT_PACKAGE_FILE_NAME ) ;
69+ assert . ok ( fs . existsSync ( enPackagePath ) , `${ DEFAULT_PACKAGE_FILE_NAME } doesn't exists` ) ;
70+ for ( const lang of SUPPORTED_LANGUAGES ) {
71+ const langPackagePath = path . join ( extension . extensionPath , `package.nls.${ lang } .json` ) ;
72+ assert . ok ( fs . existsSync ( langPackagePath ) , `package.nls.${ lang } .json doesn't exists` ) ;
73+ assert . ok ( matchKeys ( enPackagePath , langPackagePath ) , `Keys of ${ DEFAULT_PACKAGE_FILE_NAME } and package.nls.${ lang } .json don't match` ) ;
74+ }
75+ } ) ;
7876
77+ // Check localisable fields being appropriately localised for the contributes defined in package.json
78+ test ( "Localisable fields in package.json localised properly " , async ( ) => {
79+ const extension = extensions . getExtension ( EXTENSION_NAME ) ;
80+ assert ( extension ) ;
81+ const packagePath = path . join ( extension . extensionPath , "package.json" ) ;
82+ assert . ok ( fs . existsSync ( packagePath ) , "package.json doesn't exists" ) ;
83+ const enPackagePath = path . join ( extension . extensionPath , DEFAULT_PACKAGE_FILE_NAME ) ;
84+ assert . ok ( fs . existsSync ( enPackagePath ) , `${ DEFAULT_PACKAGE_FILE_NAME } doesn't exists` ) ;
85+ const validKeys : Set < string > = getKeysFromJSON ( enPackagePath ) ;
86+ const packageObj = JSON . parse ( fs . readFileSync ( packagePath , 'utf8' ) ) ;
87+ const contributes = packageObj . contributes
88+ assert . ok ( checkCommandsLocalisation ( contributes . commands , validKeys ) , "Error some commands not localized" ) ;
89+ assert . ok ( checkViewsLocalisation ( contributes . views , validKeys ) , "Error some views is not localized" ) ;
90+ assert . ok ( checkDebuggersLocalisation ( contributes . debuggers , validKeys ) , "Error some debugger labels not localized" ) ;
91+ assert . ok ( checkConfigurationLocalisation ( contributes . configuration , validKeys ) , "Error some configuration labels not localized" ) ;
92+ } ) ;
7993
80- // Check if l10n.value is called with a valid key and the placeholder map has all the keys as required in the string template
81- test ( "Proper usage of l10n.value for localisation in the ts/js code files" , async ( ) => {
82- const ignoredDirEntriesNames = new Set ( [ "test" ] ) ; // Names of folders,files( .js only),subfolders within the out directory which are not to be checked
83- const extension = vscode . extensions . getExtension ( EXTENSION_NAME ) ;
84- assert ( extension , "extension not found" ) ;
85- const enBundlePath = path . join ( extension . extensionPath , "l10n" , DEFAULT_BUNDLE_FILE_NAME ) ;
86- assert ( enBundlePath , `${ DEFAULT_BUNDLE_FILE_NAME } not found` ) ;
87- const validKeyValues = JSON . parse ( fs . readFileSync ( enBundlePath , 'utf8' ) ) ;
88- assert ( checkL10nUsageInFiles ( path . join ( extension . extensionPath , "out" ) , ignoredDirEntriesNames , validKeyValues ) === 0 , "Some files have invalid localisation keys used. Check the logs or error messages" ) ;
89- } ) ;
94+
95+ // Check if l10n.value is called with a valid key and the placeholder map has all the keys as required in the string template
96+ test ( "Proper usage of l10n.value for localisation in the ts/js code files" , async ( ) => {
97+ const ignoredDirEntriesNames = new Set ( [ "test" ] ) ; // Names of folders,files( .js only),subfolders within the out directory which are not to be checked
98+ const extension = vscode . extensions . getExtension ( EXTENSION_NAME ) ;
99+ assert ( extension , "extension not found" ) ;
100+ const enBundlePath = path . join ( extension . extensionPath , "l10n" , DEFAULT_BUNDLE_FILE_NAME ) ;
101+ assert ( enBundlePath , `${ DEFAULT_BUNDLE_FILE_NAME } not found` ) ;
102+ const validKeyValues = JSON . parse ( fs . readFileSync ( enBundlePath , 'utf8' ) ) ;
103+ assert ( checkL10nUsageInFiles ( path . join ( extension . extensionPath , "out" ) , ignoredDirEntriesNames , validKeyValues ) === 0 , "Some files have invalid localisation keys used. Check the logs or error messages" ) ;
104+ } ) ;
90105
91106} ) ;
0 commit comments