1+ import * as fs from "fs" ;
12import * as os from "os" ;
3+ import * as path from "path" ;
4+ import * as util from "util" ;
25import * as platform from "vs/base/common/platform" ;
36import * as browser from "vs/base/browser/browser" ;
7+ import * as nls from "vs/nls" ;
8+ import * as lp from "vs/base/node/languagePacks" ;
49
510// tslint:disable no-any to override const
611
7- // Use en instead of en-US since that's vscode default and it uses
8- // that to determine whether to output aliases which will be redundant.
12+ interface IBundledStrings {
13+ [ moduleId : string ] : string [ ] ;
14+ }
15+
16+ const rawNlsConfig = process . env . VSCODE_NLS_CONFIG ;
17+ if ( rawNlsConfig ) {
18+ const nlsConfig = JSON . parse ( rawNlsConfig ) as lp . InternalNLSConfiguration ;
19+ const resolved = nlsConfig . availableLanguages [ "*" ] ;
20+ ( platform as any ) . locale = nlsConfig . locale ;
21+ ( platform as any ) . language = resolved ? resolved : "en" ;
22+ ( platform as any ) . translationsConfigFile = nlsConfig . _translationsConfigFile ;
23+
24+ // TODO: Each time this is imported, VS Code's loader creates a different
25+ // module with an array of all the translations for that file. We don't use
26+ // their loader (we're using Webpack) so we need to figure out a good way to
27+ // handle that.
28+ if ( nlsConfig . _resolvedLanguagePackCoreLocation ) {
29+ const bundles = Object . create ( null ) ;
30+ ( nls as any ) . load ( "nls" , undefined , ( mod : any ) => {
31+ Object . keys ( mod ) . forEach ( ( k ) => ( nls as any ) [ k ] = mod [ k ] ) ;
32+ } , {
33+ "vs/nls" : {
34+ ...nlsConfig ,
35+ // Taken from lib/vscode/src/bootstrap.js.
36+ loadBundle : async (
37+ bundle : string , language : string ,
38+ cb : ( error ?: Error , messages ?: string [ ] | IBundledStrings ) => void ,
39+ ) : Promise < void > => {
40+ let result = bundles [ bundle ] ;
41+ if ( result ) {
42+ return cb ( undefined , result ) ;
43+ }
44+
45+ const bundleFile = path . join ( nlsConfig . _resolvedLanguagePackCoreLocation , bundle . replace ( / \/ / g, "!" ) + ".nls.json" ) ;
46+
47+ try {
48+ const content = await util . promisify ( fs . readFile ) ( bundleFile , "utf8" ) ;
49+ bundles [ bundle ] = JSON . parse ( content ) ;
50+ cb ( undefined , bundles [ bundle ] ) ;
51+ } catch ( error ) {
52+ cb ( error , undefined ) ;
53+ }
54+ } ,
55+ } ,
56+ } ) ;
57+ }
58+ }
59+
60+ // Anything other than "en" will cause English aliases to display, which ends up
61+ // just displaying a lot of redundant text when the locale is en-US.
962if ( platform . locale === "en-US" ) {
1063 ( platform as any ) . locale = "en" ;
1164}
@@ -20,8 +73,12 @@ if (platform.language === "en-US") {
2073( platform as any ) . isLinux = os . platform ( ) === "linux" ;
2174( platform as any ) . isWindows = os . platform ( ) === "win32" ;
2275( platform as any ) . isMacintosh = os . platform ( ) === "darwin" ;
23- ( platform as any ) . platform = os . platform ( ) === "linux" ? platform . Platform . Linux : os . platform ( ) === "win32" ? platform . Platform . Windows : platform . Platform . Mac ;
76+ ( platform as any ) . platform = os . platform ( ) === "linux"
77+ ? platform . Platform . Linux : os . platform ( ) === "win32"
78+ ? platform . Platform . Windows : platform . Platform . Mac ;
2479
2580// This is used for keybindings, and in one place to choose between \r\n and \n
2681// (which we change to use platform.isWindows instead).
27- ( platform as any ) . OS = ( browser . isMacintosh ? platform . OperatingSystem . Macintosh : ( browser . isWindows ? platform . OperatingSystem . Windows : platform . OperatingSystem . Linux ) ) ;
82+ ( platform as any ) . OS = browser . isMacintosh
83+ ? platform . OperatingSystem . Macintosh : browser . isWindows
84+ ? platform . OperatingSystem . Windows : platform . OperatingSystem . Linux ;
0 commit comments