@@ -9,7 +9,7 @@ import { Routing } from './router.ts'
9
9
import { colors , ensureDir , path , ServerRequest , Sha1 , walk } from './std.ts'
10
10
import { compile } from './tsc/compile.ts'
11
11
import type { AlephRuntime , APIHandle , Config , RouterURL } from './types.ts'
12
- import util , { existsDirSync , existsFileSync , hashShort , reHashJs , reHttp , reMDExt , reModuleExt , reStyleModuleExt } from './util.ts'
12
+ import util , { existsDirSync , existsFileSync , hashShort , reHashJs , reHttp , reLocaleID , reMDExt , reModuleExt , reStyleModuleExt } from './util.ts'
13
13
import { cleanCSS , Document , less } from './vendor/mod.ts'
14
14
import { version } from './version.ts'
15
15
@@ -54,6 +54,7 @@ export class Project {
54
54
outputDir : '/dist' ,
55
55
baseUrl : '/' ,
56
56
defaultLocale : 'en' ,
57
+ locales : [ ] ,
57
58
ssr : {
58
59
fallback : '404.html'
59
60
} ,
@@ -206,7 +207,7 @@ export class Project {
206
207
{ src : path . join ( baseUrl , `/_aleph/main.${ mainModule . hash . slice ( 0 , hashShort ) } .js` ) , type : 'module' } ,
207
208
{ src : path . join ( baseUrl , `/_aleph/-/deno.land/x/aleph/nomodule.js${ this . isDev ? '?dev' : '' } ` ) , nomodule : true } ,
208
209
] ,
209
- body : `<main></ main>` ,
210
+ body : `<main><p><em>Loading...</em></p></ main>` , // todo: custom `loading` page
210
211
minify : ! this . isDev
211
212
} )
212
213
return html
@@ -346,6 +347,7 @@ export class Project {
346
347
buildTarget,
347
348
sourceMap,
348
349
defaultLocale,
350
+ locales,
349
351
ssr,
350
352
env
351
353
} = config
@@ -367,6 +369,10 @@ export class Project {
367
369
if ( util . isNEString ( defaultLocale ) ) {
368
370
Object . assign ( this . config , { defaultLocale } )
369
371
}
372
+ if ( util . isArray ( locales ) ) {
373
+ Object . assign ( this . config , { locales : Array . from ( new Set ( locales . filter ( l => reLocaleID . test ( l ) ) ) ) } )
374
+ locales . filter ( l => ! reLocaleID . test ( l ) ) . forEach ( l => log . warn ( `invalid locale ID '${ l } '` ) )
375
+ }
370
376
if ( typeof ssr === 'boolean' ) {
371
377
Object . assign ( this . config , { ssr } )
372
378
} else if ( util . isPlainObject ( ssr ) ) {
@@ -381,7 +387,7 @@ export class Project {
381
387
// Gen build ID after config loaded.
382
388
this . #buildID = ( new Sha1 ( ) ) . update ( this . mode + '.' + this . config . buildTarget + '.' + version ) . hex ( ) . slice ( 0 , 18 )
383
389
// Update routing options.
384
- this . #routing = new Routing ( [ ] , this . config . baseUrl , this . config . defaultLocale , [ ] )
390
+ this . #routing = new Routing ( [ ] , this . config . baseUrl , this . config . defaultLocale , this . config . locales )
385
391
}
386
392
387
393
private async _init ( ) {
0 commit comments