mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-09-29 16:18:22 +00:00
Prepare for selecting languages
UI language is stored in user settings for authenticated users; otherwise is only stored in the current model (not persisted).
This commit is contained in:
87
modules/webapp/src/main/elm/Messages.elm
Normal file
87
modules/webapp/src/main/elm/Messages.elm
Normal file
@@ -0,0 +1,87 @@
|
||||
module Messages exposing
|
||||
( Messages
|
||||
, fromIso2
|
||||
, get
|
||||
, toIso2
|
||||
)
|
||||
|
||||
import Messages.App
|
||||
import Messages.LoginPage
|
||||
import UiLanguage exposing (UiLanguage(..))
|
||||
|
||||
|
||||
{-| The messages record contains all strings used in the application.
|
||||
-}
|
||||
type alias Messages =
|
||||
{ lang : UiLanguage
|
||||
, iso2 : String
|
||||
, label : String
|
||||
, flagIcon : String
|
||||
, app : Messages.App.Texts
|
||||
, login : Messages.LoginPage.Texts
|
||||
}
|
||||
|
||||
|
||||
get : UiLanguage -> Messages
|
||||
get lang =
|
||||
case lang of
|
||||
English ->
|
||||
gb
|
||||
|
||||
German ->
|
||||
de
|
||||
|
||||
|
||||
{-| Get a ISO-3166-1 code of the given lanugage.
|
||||
-}
|
||||
toIso2 : UiLanguage -> String
|
||||
toIso2 lang =
|
||||
get lang |> .iso2
|
||||
|
||||
|
||||
{-| Return the UiLanguage from given iso2 code. If the iso2 code is not
|
||||
known, return Nothing.
|
||||
-}
|
||||
readIso2 : String -> Maybe UiLanguage
|
||||
readIso2 iso =
|
||||
let
|
||||
isIso lang =
|
||||
iso == toIso2 lang
|
||||
in
|
||||
List.filter isIso UiLanguage.all
|
||||
|> List.head
|
||||
|
||||
|
||||
{-| return the language from the given iso2 code. if the iso2 code is
|
||||
not known, return English as a default.
|
||||
-}
|
||||
fromIso2 : String -> UiLanguage
|
||||
fromIso2 iso =
|
||||
readIso2 iso
|
||||
|> Maybe.withDefault English
|
||||
|
||||
|
||||
|
||||
--- Messages Definitions
|
||||
|
||||
|
||||
gb : Messages
|
||||
gb =
|
||||
{ lang = English
|
||||
, iso2 = "gb"
|
||||
, label = "English"
|
||||
, flagIcon = "flag-icon flag-icon-gb"
|
||||
, app = Messages.App.gb
|
||||
, login = Messages.LoginPage.gb
|
||||
}
|
||||
|
||||
|
||||
de : Messages
|
||||
de =
|
||||
{ lang = German
|
||||
, iso2 = "de"
|
||||
, label = "Deutsch"
|
||||
, flagIcon = "flag-icon flag-icon-de"
|
||||
, app = Messages.App.de
|
||||
, login = Messages.LoginPage.de
|
||||
}
|
Reference in New Issue
Block a user