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

Usage in background/isolate #198

Closed
kuhnroyal opened this issue Jun 8, 2020 · 11 comments
Closed

Usage in background/isolate #198

kuhnroyal opened this issue Jun 8, 2020 · 11 comments
Labels
question Further information is requested

Comments

@kuhnroyal
Copy link

I didn't find a way to access the translations without a Widget tree, for example in a background isolate. All the initialization is happening in the EasyLocalization class and everything is private.

Is there a way to achieve something like this or is such support planned?

@Overman775
Copy link
Collaborator

@kuhnroyal What is the problem of transferring ready-made translated data to isolate?

@Overman775 Overman775 added the question Further information is requested label Jun 8, 2020
@kuhnroyal
Copy link
Author

I am generating a PDF in a background isolate. The app might not be running so I can no access the EasyLocalization/Translations.

@Overman775
Copy link
Collaborator

@kuhnroyal you can pass context to isolate and work with translations

@kuhnroyal
Copy link
Author

That is my problem, I don't have a context.

@Overman775
Copy link
Collaborator

@kuhnroyal you try past context in constructor? This is just an assumption, I did not work with isolates..

@kuhnroyal
Copy link
Author

The BuildContext is only available when the app is actually running. In a background service there is no BuildContext. I need to get the Localization.instance and it needs to be set beforehand but this only happens in the EasyLocalization widget.

@kuhnroyal
Copy link
Author

If the src/localization.dart and src/translation.dart files are to be exported. Then I can manually use an AssetLoader to set the instance.

@ncuillery
Copy link

@kuhnroyal you can import them. Since they aren't public, they don't show up in Autocomplete/Quick Fix from the IDE, but you can type the import by hand:

import 'package:easy_localization/src/localization.dart';
import 'package:easy_localization/src/translations.dart';

and use classes from those files.

@AhmetMelihSerter
Copy link

I didn't find a way to access the translations without a Widget tree, for example in a background isolate. All the initialization is happening in the EasyLocalization class and everything is private.

Is there a way to achieve something like this or is such support planned?

If you wrote, can you share it on your github account?

@jonasN5
Copy link

jonasN5 commented Mar 23, 2021

If the src/localization.dart and src/translation.dart files are to be exported. Then I can manually use an AssetLoader to set the instance.

Did you manage to do that? I have the exact same problem, typically happens for background notifications, where BuildContext is not available.

@AhmetMelihSerter
Copy link

If the src/localization.dart and src/translation.dart files are to be exported. Then I can manually use an AssetLoader to set the instance.

Did you manage to do that? I have the exact same problem, typically happens for background notifications, where BuildContext is not available.

I tried it works. Thanks.

#210 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants