ChristophP / elm-i18next

https://package.elm-lang.org/packages/ChristophP/elm-i18next/latest
BSD 3-Clause "New" or "Revised" License
67 stars 13 forks source link

Translations always showing keys instead of values? #39

Closed andreacfromtheapp closed 2 years ago

andreacfromtheapp commented 2 years ago

Hi @ChristophP

Thank you for this package, it looks amazing. Not sure if this is an issue, or it's me. I've tried pinging you on slack, before opening this issue. Since I'm not sure what's going on, it could be a bug or not. I believe I've done everything right, but all I get are keys rather than values. I believe that t is always returning the Maybe.withDefault key for some reason.

Here are a few details:

elm-i18next-gen --source public/translations/translations.en.json --target src/elm --overwrite

{
  "init": {
    "api": "https://random-words-api.vercel.app/word",
    "message": "START TYPING TO MATCH THE WORD ABOVE"
  },
  "screen": {
    "word": "Your word is:",
    "definition": "Definition:",
    "pronunciation": "Pronunciation:"
  },
  "command": {
    "erase": "ERASE [↤]",
    "reset": "RESET [5]",
    "speak": "SPEAK [8]",
    "spell": "SPELL [9]",
    "submit": "SUBMIT [↵]",
    "retry": "RETRY [6]",
    "new": "NEW [0]",
    "soundOn": "SOUND ON [2]",
    "soundOff": "SOUND OFF [3]"
  }
}
// translations defaults to English
let translations = fetch('translations/translations.en.json')

// Start the Elm application.
const app = Elm.SpeakAndSpell.init({
  node: document.querySelector('main'),
  flags: translations
})

// Language select for the translation file
app.ports.language.subscribe(function (message) {
  translations = fetch('translations/translations.' + message + '.json')
})
initialModel : Encode.Value -> ( Model, Cmd Msg )
initialModel encodedJson =
    let
        initLocale : Translations
        initLocale =
            case Decode.decodeValue translationsDecoder encodedJson of
                Ok translations ->
                    translations

                Err _ ->
                    initialTranslations
    in
    ( { status = Loading
      , output = Init
      , sound = On
      , lang = En
      , translations = initLocale
      , newWord =
            { word = "INIT"
            , definition = ""
            , pronunciation = ""
            }
      , guessWord = ""
      , checkWord = ""
      , result = ""
      }
    , getNewWordCmd
    )
import Translations.Init as TRinit

outputText : Model -> String
outputText model =
    case model.output of
        Init ->
            TRinit.message model.translations
                |> String.toUpper

        Word ->
            model.guessWord

        Result ->
            model.result

Please and thank you

ChristophP commented 2 years ago

Bug found in JS that passes translations to Elm.