matice icon indicating copy to clipboard operation
matice copied to clipboard

Fallback locale not working

Open Coding-Kiwi opened this issue 2 years ago • 8 comments

Situation: the locale is "de", the fallback locale is "en" and there are only translations for "en"

Expected behavior

calling the trans( function should output an 'en' translation

Current behavior

matice throws a Locale [de] does not exist. error. This happens because the findSentence immediately calls the translations function which does not check the fallbackLocale variable and thus fails.

Versions

  • Laravel: 8.75.0
  • Matice: 1.1.6

Coding-Kiwi avatar Jan 06 '22 13:01 Coding-Kiwi

Hi! Let me take a look,

GENL avatar Jan 08 '22 11:01 GENL

Are you using the CDN or the NPM package ?

GENL avatar Feb 08 '22 11:02 GENL

Are you using the CDN or the NPM package ?

Npm package, newest version

Coding-Kiwi avatar Feb 08 '22 11:02 Coding-Kiwi

Are you still having the same problem with this version?

GENL avatar Feb 08 '22 11:02 GENL

Are you still having the same problem with this version?

I will check when I get back home 👍

Coding-Kiwi avatar Feb 08 '22 11:02 Coding-Kiwi

Alright. Waiting...

GENL avatar Feb 08 '22 11:02 GENL

@GENL For the npm bundle I'm using the latest version 1.1.4, checked with npm view matice For the composer package I'm using the latest version 1.1.7, checked with composer show genl/matice

As expected, still receiving the Locale [de] does not exist. Error because the findSentence function immediately calls the translations function which does not check the fallbackLocale variable and thus fails.

https://github.com/GENL/matice/blob/1.1.x/src/js/Localization/core.ts#L60

Coding-Kiwi avatar Feb 13 '22 13:02 Coding-Kiwi

I've found a way to solve this issue for now.

Matice needs at least one translation file for any locale you want to specify. For now you can add a directory with your locale and php-file inside with the following content:

<?php
# resources/lang/de/placeholder.php
return (object) [];

This allows the fallback to work correctly. No the prettiest solution, but it works.

rediche avatar Nov 07 '22 13:11 rediche