Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use translation service programmatically #63

Closed
t0nyak opened this issue Sep 5, 2019 · 4 comments
Closed

Unable to use translation service programmatically #63

t0nyak opened this issue Sep 5, 2019 · 4 comments

Comments

@t0nyak
Copy link

t0nyak commented Sep 5, 2019

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

Translation programmatically is not working at all.

Expected behavior

Being able to translate somehow in the component.

Minimal reproduction of the problem with instructions

  1. Inject transloco service in the component where I want to use it
  2. Call translate() method with the exact string to the value to be translated like this: this.service.translate('section.subsection.value')
  3. It returns nothing

No matter if I inject the service using constructor(private service: TranslocoService) {} or I directly import translate() function. Both of them do nothing.

I know the path to the value in the translation files is correct, since it works using the template approach.

By the way, I'm not providing a stackblitz demo since I've not been able even to reproduce the transloco-example in the stackblitz. Is the project and the demo still being supported?

Environment


Angular version: 8.0.1


Browser:
- [x] 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: 10.16.0  
- Platform: Mac 

Others:

@itayod
Copy link
Contributor

itayod commented Sep 5, 2019

Hi @t0nyak,

Your problem is that the translation files did not successfully load yet when you tried to use the tranlate method.

From the docs:
"Note that in order to safely use this method, you are responsible for ensuring that the translation files have been successfully loaded by the time it's called. If you aren't sure, you can use the selectTranslate() method instead"

@itayod itayod closed this as completed Sep 5, 2019
@gs-mhashir
Copy link

how to load the translation files before calling any method

@sysmat
Copy link

sysmat commented Dec 20, 2023

Note that in order to safely use this method, you are responsible for ensuring that the translation files have been successfully loaded by the time it's called.

is this possible ? If not translate method should be removed

@shaharkazaz
Copy link
Collaborator

@sysmat @gs-mhashir I recommended reading the docs.

@jsverse jsverse locked and limited conversation to collaborators Dec 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants