@@ -3,10 +3,12 @@ package main
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "errors"
6
7
"fmt"
7
8
"io/ioutil"
8
9
"log"
9
10
"net/http"
11
+ "regexp"
10
12
"sort"
11
13
"strings"
12
14
@@ -23,6 +25,7 @@ import (
23
25
const DefaultServiceAccountName string = "default-editor"
24
26
const SharedMemoryVolumeName string = "dshm"
25
27
const SharedMemoryVolumePath string = "/dev/shm"
28
+ const EnvKfLanguage string = "KF_LANG"
26
29
27
30
type volumetype string
28
31
@@ -61,6 +64,7 @@ type newnotebookrequest struct {
61
64
DataVolumes []volumerequest `json:"datavols"`
62
65
EnableSharedMemory bool `json:"shm"`
63
66
Configurations []string `json:"configurations"`
67
+ Language string `json:"language"`
64
68
}
65
69
66
70
type notebookresponse struct {
@@ -471,6 +475,19 @@ func (s *server) NewNotebook(w http.ResponseWriter, r *http.Request) {
471
475
}
472
476
}
473
477
478
+ //Add Language
479
+ //Validate that the language format is valid (language[_territory])
480
+ match , err := regexp .MatchString ("^[[:alpha:]]{2}(_[[:alpha:]]{2})?$" , req .Language )
481
+ if (err != nil || ! match ) {
482
+ var errLanguageFormat = errors .New ("Error: the value of KF_LANG environment variable ('" + req .Language + "') is not a valid format (e.g 'en', 'en_US', ...)" )
483
+ s .error (w , r , errLanguageFormat )
484
+ return
485
+ }
486
+ notebook .Spec .Template .Spec .Containers [0 ].Env = append (notebook .Spec .Template .Spec .Containers [0 ].Env , corev1.EnvVar {
487
+ Name : EnvKfLanguage ,
488
+ Value : req .Language ,
489
+ })
490
+
474
491
log .Printf ("creating notebook %q for %q" , notebook .ObjectMeta .Name , namespace )
475
492
476
493
// Submit the notebook to the API server
0 commit comments