From c97673c55cf12b880d6177a143aa2b4dc112fded Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 8 Feb 2017 19:25:08 -0800 Subject: [PATCH] Make categories localizable --- src/compiler/commandLineParser.ts | 153 ++++++++++++++------------- src/compiler/diagnosticMessages.json | 33 ++++++ src/compiler/types.ts | 2 +- 3 files changed, 111 insertions(+), 77 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index adbb879d5ec..46327668f26 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -15,7 +15,7 @@ namespace ts { shortName: "h", type: "boolean", showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, description: Diagnostics.Print_this_message, }, { @@ -27,7 +27,7 @@ namespace ts { name: "all", type: "boolean", showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, description: Diagnostics.Show_all_compiler_options, }, { @@ -35,14 +35,14 @@ namespace ts { shortName: "v", type: "boolean", showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, description: Diagnostics.Print_the_compiler_s_version, }, { name: "init", type: "boolean", showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, description: Diagnostics.Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file, }, { @@ -51,7 +51,7 @@ namespace ts { type: "string", isFilePath: true, showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, paramType: Diagnostics.FILE_OR_DIRECTORY, description: Diagnostics.Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json, }, @@ -59,7 +59,7 @@ namespace ts { name: "pretty", type: "boolean", showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental }, { @@ -67,7 +67,7 @@ namespace ts { shortName: "w", type: "boolean", showInSimplifiedHelpView: true, - category: "CommandLine", + category: Diagnostics.CommandLine_Options, description: Diagnostics.Watch_input_files, }, @@ -86,7 +86,7 @@ namespace ts { }), paramType: Diagnostics.VERSION, showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_or_ESNEXT, }, { @@ -103,7 +103,7 @@ namespace ts { }), paramType: Diagnostics.KIND, showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015, }, { @@ -141,14 +141,14 @@ namespace ts { }), }, showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon }, { name: "allowJs", type: "boolean", showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Allow_javascript_files_to_be_compiled }, { @@ -160,7 +160,7 @@ namespace ts { }), paramType: Diagnostics.KIND, showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_react_native_or_react, }, { @@ -168,14 +168,14 @@ namespace ts { shortName: "d", type: "boolean", showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Generates_corresponding_d_ts_file, }, { name: "sourceMap", type: "boolean", showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Generates_corresponding_map_file, }, { @@ -184,7 +184,7 @@ namespace ts { isFilePath: true, paramType: Diagnostics.FILE, showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Concatenate_and_emit_output_to_single_file, }, { @@ -193,7 +193,7 @@ namespace ts { isFilePath: true, paramType: Diagnostics.DIRECTORY, showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Redirect_output_structure_to_the_directory, }, { @@ -201,7 +201,7 @@ namespace ts { type: "string", isFilePath: true, paramType: Diagnostics.LOCATION, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir, }, { @@ -209,39 +209,39 @@ namespace ts { type: "string", isFilePath: true, paramType: Diagnostics.DIRECTORY, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Output_directory_for_generated_declaration_files }, { name: "removeComments", type: "boolean", showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Do_not_emit_comments_to_output, }, { name: "noEmit", type: "boolean", showInSimplifiedHelpView: true, - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Do_not_emit_outputs, }, { name: "importHelpers", type: "boolean", - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Import_emit_helpers_from_tslib }, { name: "skipLibCheck", type: "boolean", - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Skip_type_checking_of_declaration_files, }, { name: "isolatedModules", type: "boolean", - category: "Basic", + category: Diagnostics.Basic_Options, description: Diagnostics.Unconditionally_emit_imports_for_unresolved_files }, @@ -250,86 +250,86 @@ namespace ts { name: "noImplicitAny", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type, }, { name: "strictNullChecks", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Enable_strict_null_checks }, { name: "noImplicitThis", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type, }, { name: "noUnusedLocals", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Report_errors_on_unused_locals, }, { name: "noUnusedParameters", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Report_errors_on_unused_parameters, }, { name: "alwaysStrict", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Parse_in_strict_mode_and_emit_use_strict_for_each_source_file }, { name: "noImplicitReturns", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Report_error_when_not_all_code_paths_in_function_return_a_value }, { name: "noFallthroughCasesInSwitch", type: "boolean", showInSimplifiedHelpView: true, - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement }, { name: "allowUnusedLabels", type: "boolean", - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Do_not_report_errors_on_unused_labels }, { name: "allowUnreachableCode", type: "boolean", - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Do_not_report_errors_on_unreachable_code }, { name: "suppressExcessPropertyErrors", type: "boolean", - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Suppress_excess_property_checks_for_object_literals, }, { name: "suppressImplicitAnyIndexErrors", type: "boolean", - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures, }, { name: "forceConsistentCasingInFileNames", type: "boolean", - category: "StrictChecks", + category: Diagnostics.Strict_Checks, description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file }, @@ -341,14 +341,14 @@ namespace ts { "classic": ModuleResolutionKind.Classic, }), paramType: Diagnostics.STRATEGY, - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, }, { name: "baseUrl", type: "string", isFilePath: true, - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.Base_directory_to_resolve_non_absolute_module_names }, { @@ -357,7 +357,7 @@ namespace ts { name: "paths", type: "object", isTSConfigOnly: true, - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.List_of_path_mapping_entries_for_module_names_to_locations_relative_to_the_baseUrl }, @@ -372,7 +372,7 @@ namespace ts { type: "string", isFilePath: true }, - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.List_of_root_folders_whose_combined_content_represent_the_structure_of_the_project_at_runtime }, { @@ -383,7 +383,7 @@ namespace ts { type: "string", isFilePath: true }, - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.List_of_folders_to_include_type_definitions_from }, { @@ -394,19 +394,19 @@ namespace ts { type: "string" }, showInSimplifiedHelpView: true, - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.Type_declaration_files_to_be_included_in_compilation }, { name: "allowSyntheticDefaultImports", type: "boolean", - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking }, { name: "maxNodeModuleJsDepth", type: "number", - category: "ModuleResolution", + category: Diagnostics.Module_Resolution_Options, description: Diagnostics.The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files }, @@ -416,7 +416,7 @@ namespace ts { type: "string", isFilePath: true, paramType: Diagnostics.LOCATION, - category: "SourceMaps", + category: Diagnostics.SourceMap_Options, description: Diagnostics.Specify_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, }, { @@ -424,19 +424,19 @@ namespace ts { type: "string", isFilePath: true, paramType: Diagnostics.LOCATION, - category: "SourceMaps", + category: Diagnostics.SourceMap_Options, description: Diagnostics.Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, }, { name: "inlineSourceMap", type: "boolean", - category: "SourceMaps", + category: Diagnostics.SourceMap_Options, description: Diagnostics.Emit_a_single_file_with_source_maps_instead_of_having_a_separate_file }, { name: "inlineSources", type: "boolean", - category: "SourceMaps", + category: Diagnostics.SourceMap_Options, description:Diagnostics.Emit_the_source_alongside_the_sourcemaps_within_a_single_file_requires_inlineSourceMap_or_sourceMap_to_be_set }, @@ -444,7 +444,7 @@ namespace ts { { name: "jsxFactory", type: "string", - category: "JSX", + category: Diagnostics.JSX_Options, description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h }, @@ -452,13 +452,13 @@ namespace ts { { name: "experimentalDecorators", type: "boolean", - category: "Experimental", + category: Diagnostics.Experimental_Options, description: Diagnostics.Enables_experimental_support_for_ES7_decorators }, { name: "emitDecoratorMetadata", type: "boolean", - category: "Experimental", + category: Diagnostics.Experimental_Options, description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators }, @@ -466,31 +466,31 @@ namespace ts { { name: "diagnostics", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Show_diagnostic_information }, { name: "extendedDiagnostics", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Show_extended_diagnostic_information }, { name: "traceResolution", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Enable_tracing_of_the_name_resolution_process }, { name: "listFiles", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Print_names_of_files_part_of_the_compilation }, { name: "listEmittedFiles", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Print_names_of_generated_files_part_of_the_compilation }, @@ -499,40 +499,40 @@ namespace ts { type: "string", isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files // for correct behaviour, please use outFile - category: "Advanced", + category: Diagnostics.Advanced_Options, paramType: Diagnostics.FILE, description: Diagnostics.Deprecated_Use_outFile_instead_Concatenate_and_emit_output_to_single_file, }, { name: "reactNamespace", type: "string", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react_JSX_emit }, { name: "skipDefaultLibCheck", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Deprecated_Use_skipLibCheck_instead_Skip_type_checking_of_default_library_declaration_files }, { name: "charset", type: "string", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.The_character_set_of_the_input_files }, compileOnSaveCommandLineOption, { name: "emitBOM", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description:Diagnostics.Emit_a_UTF_8_Byte_Order_Mark_BOM_in_the_beginning_of_output_files }, { name: "locale", type: "string", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.The_locale_to_use_to_show_error_messages_e_g_en_us }, { @@ -542,61 +542,61 @@ namespace ts { "lf": NewLineKind.LineFeed }), paramType: Diagnostics.NEWLINE, - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix, }, { name: "noErrorTruncation", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_truncation_error_messages }, { name: "noLib", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_include_the_default_library_file_lib_d_ts }, { name: "noResolve", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description:Diagnostics.Do_not_add_triple_slash_references_or_module_import_targets_to_the_list_of_compiled_files }, { name: "stripInternal", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation, }, { name: "disableSizeLimit", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Disable_size_limitation_on_JavaScript_project }, { name: "noImplicitUseStrict", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output }, { name: "noEmitHelpers", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_generate_custom_helper_functions_like_extends_in_compiled_output }, { name: "noEmitOnError", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported, }, { name: "preserveConstEnums", type: "boolean", - category: "Advanced", + category: Diagnostics.Advanced_Options, description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code }, ]; @@ -907,7 +907,7 @@ namespace ts { if (hasProperty(options, name)) { // tsconfig only options cannot be specified via command line, // so we can assume that only types that can appear here string | number | boolean - if (optionsNameMap.has(name) && optionsNameMap.get(name).category === "CommandLine") { + if (optionsNameMap.has(name) && optionsNameMap.get(name).category === Diagnostics.CommandLine_Options) { continue; } const value = options[name]; @@ -957,10 +957,11 @@ namespace ts { function writeConfigurations() { const categorizedOptions = reduceLeft( - filter(optionDeclarations, o => o.category !== "CommandLine" && o.category !== "Advanced"), + filter(optionDeclarations, o => o.category !== Diagnostics.CommandLine_Options && o.category !== Diagnostics.Advanced_Options), (memo, value) => { if (value.category) { - (memo[value.category] || (memo[value.category] = [])).push(value); + const name = getLocaleSpecificMessage(value.category); + (memo[name] || (memo[name] = [])).push(value); } return memo; }, >{}); @@ -977,7 +978,7 @@ namespace ts { result += `${tab}${tab}// ${category}${newLine}`; result += `${newLine}`; for (const option of categorizedOptions[category]) { - result += `${tab}${tab}// ${option.description && option.description.message || option.name}${newLine}`; + result += `${tab}${tab}// ${option.description && getLocaleSpecificMessage(option.description) || option.name}${newLine}`; if (option.name in configurations.compilerOptions) { result += `${tab}${tab}"${option.name}": ${JSON.stringify(configurations.compilerOptions[option.name])}${++seenKnownKeys === knownKesyCount ? "" : ","}${newLine}`; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b487b47b106..f5ee14a8cbb 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3085,6 +3085,39 @@ "category": "Message", "code": 6170 }, + "CommandLine Options": { + "category": "Message", + "code": 6171 + }, + "Basic Options": { + "category": "Message", + "code": 6172 + }, + "Strict Checks": { + "category": "Message", + "code": 6173 + }, + "Module Resolution Options": { + "category": "Message", + "code": 6174 + }, + "SourceMap Options": { + "category": "Message", + "code": 6175 + }, + "JSX Options": { + "category": "Message", + "code": 6176 + }, + "Experimental Options": { + "category": "Message", + "code": 6177 + }, + "Advanced Options": { + "category": "Message", + "code": 6178 + }, + "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 69c8d7a5c95..589c196d132 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3386,7 +3386,7 @@ isTSConfigOnly?: boolean; // True if option can only be specified via tsconfig.json file isCommandLineOnly?: boolean; showInSimplifiedHelpView?:boolean; - category?: "CommandLine" | "Basic" | "StrictChecks" | "ModuleResolution" | "JSX" | "SourceMaps" | "Experimental" | "Advanced"; + category?: DiagnosticMessage; } /* @internal */