GENL / matice

Use your Laravel translations in JavaScript.
MIT License
99 stars 15 forks source link

window.navigator.language and navigator.language does not return same language as getLocale() #26

Closed kasperwandahl closed 3 years ago

kasperwandahl commented 3 years ago

Expected behavior

I've installed this in laravel project with jetstream.

  1. Add @translations to app.blade.php in header
  2. Ran composer require genl/matice and npm install matice
  3. Added the import and methods in app.js
  4. Added translations for both da and da-DK and would expect this work when my browser is da-DK

So basics issue is: Matice getLocale() should return same language as window.navigator.language or navigator.language

Current behavior

For debugging I put these in app.js console.log(`Vue locale ${getLocale()}, browser locale ${navigator.language}`) console.log(locales()) with this result: Vue locale en, browser locale da-DK ["da", "da-DK", "en"]

The english translation works and it is being updated whenever I change something, but I can't get it to display the danish translation. It might very well be a mistake I made myself, but I can't pinpoint where it is.

Versions

Translations

resources/lang/da-DK/dashboard.php and same content for resources/lang/da/dashboard.php

return [
    'profile' => 'Med din FCK Profil har du alt FCK-relateret indhold samlet ét sted. Tilpas din profil, så du får lige nøjagtigt det ud af din fodboldklub, som du gerne vil have.',
];

{{ $trans('dashboard.profile') }}

Contents of Matice.translations

image

kasperwandahl commented 3 years ago

My mistake. For anyone having the same issue this package takes the locale from the config/app.php which in my case was en. If I do setLocale(navigator.language) in app.js it sets the language based on the browser locale. If users browser is in an unsupported locale, it should fallback to fallback_locale from config/app.php.