question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of useFallbackTranslation results in faulty language selection

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Setting useFallbackTranslation causes transloco to assume that the fallback language is scoped when it’s not, which results in a requested lang that has a / prefix. E.g. /en

  1. Specify a fallback fallbackLang: 'en'
  2. Setting active language to sv-SE (it should not be listed as available either)
  3. Have a missing translation for foo in sv-SE
  4. Notice that the HttpLoader getTranslation is first called with sv-SE
  5. Notice that the HttpLoader getTranslation is then called with /en

Note that the default HttpLoader most likely survives as two slashes often works:

@Injectable({ providedIn: 'root' })
export class TranslocoHttpLoader implements TranslocoLoader {
  constructor(private http: HttpClient) {}

  getTranslation(lang: string) {
    return this.http.get<Translation>(`/assets/i18n/${lang}.json`);
  }
}

With this loader the computed url would be /assets/i18n//en.json.

If the loader loads translations from an api like /lang=${lang} it will result in /lang=/en and perhaps break.

Expected behavior

A language should only be considered scoped if the language name contains a /. A fallback language maybe shouldn’t require to be under the primary language scope. Currently foo/bar will fallback to foo/${lang}.

This function that checks for scope should be checking if the language id contains a /:

  _isLangScoped(lang: string) {
    return this.getAvailableLangsIds().indexOf(lang) === -1;
  }

Workaround

Just assume the requested language exists just to avoid it being considered scoped:

transloco.setAvailableLangs([locale.language]);
const availableLanguages = transloco.getAvailableLangs() as string[];
if (!availableLanguages.includes(locale.language)) {
	// Just assume this language is available somewhere
	transloco.setAvailableLangs([...availableLanguages, locale.language]);
}
transloco.setActiveLang(locale.language);

Though this makes it harder to actually use scoped translations

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem, for that you could use our stackblitz example

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
shaharkazazcommented, Jun 8, 2020

@krokofant Seems like this is a breaking change. If there is a point where you do know the languages you add them at runtime via the API, if not you can still use your solution. Also, please check that your tests are passing before opening a PR (we also have a pre-push hook for it, you might have bypassed it)

1reaction
krokofantcommented, Jun 3, 2020

@shaharkazaz Did you see the reproduction? I could supply a PR if I get some direction

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot checking spelling and grammar in multiple ...
Checking spelling and grammar in multiple languages can present unique problems, such as correctly spelled words being flagged as incorrect, or misspelled ...
Read more >
Language Experience Changes Language and Cognitive Ability
The sustained use of two languages by bilinguals has been shown to induce broad changes in language and cognitive abilities across the lifespan....
Read more >
EFFECTIVE USE OF LANGUAGE
This can lead to poor health." In both examples above, the language that is used is unfamiliar to the readers. As a result,...
Read more >
Qualitative aspects of spoken language use - Table 3 (CEFR ...
Only a conceptually difficult subject can hinder a natural, smooth flow of language. Can select a suitable phrase from a readily available range...
Read more >
Politics and the English Language
Now, it is clear that the decline of a language must ultimately have political and economic causes: it is not due simply to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found