fix: return default language file, if requested lang does not exist for default login texts (#1988)

* fix: return default language file, if requested lang doesnt exists

* feat: read default translation file

* feat: docs
This commit is contained in:
Fabi 2021-07-08 14:01:07 +02:00 committed by GitHub
parent 10cae58505
commit c950d6d272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View File

@ -793,7 +793,7 @@ The Following Variables can be used:
> **rpc** GetDefaultLoginTexts([GetDefaultLoginTextsRequest](#getdefaultlogintextsrequest))
[GetDefaultLoginTextsResponse](#getdefaultlogintextsresponse)
Returns the default custom texts for login ui
Returns the default custom texts for login ui (translation file)

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
@ -414,6 +415,9 @@ func (repo *IAMRepository) GetDefaultLoginTexts(ctx context.Context, lang string
contents, ok := repo.TranslationFileContents[lang]
if !ok {
contents, err := repo.readTranslationFile(fmt.Sprintf("/i18n/%s.yaml", lang))
if os.IsNotExist(err) {
contents, err = repo.readTranslationFile(fmt.Sprintf("/i18n/%s.yaml", repo.SystemDefaults.DefaultLanguage.String()))
}
if err != nil {
return nil, err
}

View File

@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"time"
@ -629,6 +630,9 @@ func (repo *OrgRepository) GetDefaultLoginTexts(ctx context.Context, lang string
contents, ok := repo.TranslationFileContents[lang]
if !ok {
contents, err := repo.readTranslationFile(fmt.Sprintf("/i18n/%s.yaml", lang))
if os.IsNotExist(err) {
contents, err = repo.readTranslationFile(fmt.Sprintf("/i18n/%s.yaml", repo.SystemDefaults.DefaultLanguage.String()))
}
if err != nil {
return nil, err
}

View File

@ -1641,7 +1641,7 @@ service AdminService {
};
}
//Returns the default custom texts for login ui
//Returns the default custom texts for login ui (translation file)
rpc GetDefaultLoginTexts(GetDefaultLoginTextsRequest) returns (GetDefaultLoginTextsResponse) {
option (google.api.http) = {
get: "/text/default/login/{language}";