phrase / flutter_sdk_example Goto Github PK
View Code? Open in Web Editor NEWFlutter demo application for Phrase OTA
Flutter demo application for Phrase OTA
I'd like to be able to translate a String received from a REST API.
I'd gladly fork the SDK to implement it myself but I couldn't find the source code on Phrase's Github.
Expected method :
final stringKey = 'my_key';
final translation = AppLocalizations.of(this).translateKey(stringKey);
Hey Phrase Team!
Thanks for your great job in the first place. The current version of the phrase
package is 2.0.0 and requires package_info_plus
>=1.3.0 <4.0.0. But current package_info_plus
version is 4.0.2. It brings a lot of issues of other packages that are also dependent on package_info_plus
.
We use OTA feature from phrase on our project and we organize it as a monorepo, so we have multiple packages on the same project. For better code organization, we have split the .arb files and there is one for each package. Also aiming code organization, we customize the AppLocalizations
class name on the packages using the output-class
field from the l10n.yaml
file, so we get a more contextual Localizations class.
The issue is that the code generation tool from phrase used to generate the PhraseLocalizations
class doesn't seem to consider this field when generating the code, causing some build erros.
As a solution, we could just start considering that the AppLocalizations
may not have that exact name due to the output-class
field being set.
So, in practice, instead of generating these classes:
class _PhraseLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> { /*...*/ }
class PhraseLocalizations extends AppLocalizations { /*...*/ }
We might have something like this
class _PhraseLocalizationsDelegate extends LocalizationsDelegate<OutputClassName> { /*...*/ }
class PhraseLocalizations extends OutputClassName { /*...*/ }
for a l10n.yaml
file that looks like this
arb-dir: lib/l10n
template-arb-file: pt-BR.arb
output-localization-file: app_localizations.dart
output-dir: lib/src/l10n/generated
synthetic-package: false
output-class: OutputClassName
Error: Couldn't resolve the package 'flutter_gen' in 'package:flutter_gen/gen_l10n/phrase_localizations.dart' -
When I generate a new build locally, everything works. When I use codemagic I get errors like this.
Could something be missing in the configuration?
From codemagic:
flutter pub get
flutter packages pub run build_runner build --delete-conflicting-outputs
When I tried to use the command from the documentation it didn't help.
flutter pub get
flutter pub run phrase
flutter packages pub run build_runner build --delete-conflicting-outputs
main.dart
...
localizationsDelegates: PhraseLocalizations.localizationsDelegates,
supportedLocales: PhraseLocalizations.supportedLocales,
...
Where's the example of unit testing?
Hello,
when I create a normal phrase key in which I want to insert some value, the generated arb file looks like this:
"createPollAddUpToImages": "Add up to {value} images", "@createPollAddUpToImages": { "type": "text", "placeholders": { "value": { } } },
and in flutter I can call this key and pass the value like this:
AppLocalizations.of(context)!.createPollAddUpToImages(2)
But when I want to do the same for a key that has plural forms the generated arb file does NOT contain the placeholders value.
"hideReplyOne": "Hide 1 reply", "hideReplyOther": "Hide {value} replies", "hideReplyZero": "Hide {value} replies", "@hideReply": { "type": "text" },
Of course I cannot make use of this then:
AppLocalizations.of(context)!.hideReplyOther(4)
I could modify the file myself to make it work, but we are importing the arb files from the phrase-translations pull request and let flutter generate the localizations with flutter pub run phrase
.
And every time I have new keys my old changes would be overwritten.
Is there something I am missing? Or if not, I would really appreciate some fix for that :)
Hi all, after generated the phrase. I try to call the content dynamic by key
. I found on phrase_base.dart.dart
we can do it by this code.
Phrase.getText(localeName, key);
After testing it, it's not working.
Even I clone this project, Phrase.getText
returning null
.
AppLocalizations.of(context).textSimple; // can get value
Phrase.getText('en', 'textSimple'); // can't get value but returning null
Hi, how to modified generated code from phrase?
For example, here is the example of generated code:
abstract class AppLocalizations {
...
static AppLocalizations? of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}
...
}
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
...
@override
Future<AppLocalizations> load(Locale locale) {
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
}
...
}
AppLocalizations lookupAppLocalizations(Locale locale) {
...
}
But I need to modified that code to this:
/// new line code
Locale _currentLocale = const Locale('en');
abstract class AppLocalizations {
...
/// modified code
static AppLocalizations of() {
return lookupAppLocalizations(_currentLocale);
}
/// new line code
static Locale get currentLocale => _currentLocale;
...
}
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
...
@override
Future<AppLocalizations> load(Locale locale) {
/// new line code
_currentLocale = locale;
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
}
...
}
AppLocalizations lookupAppLocalizations(Locale locale) {
...
}
It's possible to do? if yes, can u share the docs for that or tell me how to do it?
The reason why i need to modified the generated code are:
context
(u can see first example code above) and also not testable coz of a context
.Hi, it's can be nice to have a repository "phrase-flutter" on your organisation for makings issues for this library: https://pub.dev/packages/phrase
(Because I can't find the repository related).
Thanks,
Hi
I saw a case where if I create a new OTA release, and get the values downloaded and saved on my local device. Now if I want to use the embedded values in the .arb files packed in the APK, I simply can't do that.
I tried deleting the release created. It gives a 404 error but still takes the value for a key from the cached value. I tried deleting the distribution as well and achieved the same 404 error. Now I don't have a way to clear the cached values on a user's device.
I was looking to fork the repo, and do the modification, but couldn't find the public repo for flutter SDK. Hence creating an issue on the example package.
The Phrase SDK is depending on package_info_plus
package.
The current version of package_info_plus
is 3.1.0
The current version used in phrase is 1.3.0
Could you please update it ?
When trying to upgrade my project to use flutter 3.13.3, I've upgraded phrase to latest 2.1.1 version but when running flutter pub run phrase I'm getting the following error:
$ flutter pub run phrase
Failed to build phrase:phrase:
../../../.pub-cache/hosted/pub.dev/watcher-1.0.1/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
abstract class _ConstructableFileSystemEvent implements FileSystemEvent {
I'm still not 100% sure that this error is something specific from phrase, but I'm issuing this bug in case someone can take a look already since it's blocking us from upgrading our project's flutter version.
Please let me know if you need more information, and thanks in advance ๐
Hi team, I can generated the phrase code by flutter_gen locally using flutter pub run phrase
, so no error was found in my code.
code usage
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_gen/gen_l10n/phrase_localizations.dart';
class LocalizationTest {
const LocalizationTest({required this.context});
final BuildContext context;
AppLocalizations get tr => AppLocalizations.of(context);
String getString(String key) {
Locale currentLocale = Localizations.localeOf(context);
String localeCode = Intl.canonicalizedLocale(currentLocale.toString());
return Phrase.getText(localeCode, key) ?? key;
}
List<LocalizationsDelegate> get localizationsDelegates =>
PhraseLocalizations.localizationsDelegates;
List<Locale> get supportedLocales => PhraseLocalizations.supportedLocales;
}
l10n.yaml file
# Where to find translation files
arb-dir: lib/localization/l10n
# Which translation is the default/template
template-arb-file: app_de.arb
# What to call generated dart files
output-localization-file: app_localizations.dart
output-dir: lib/localization/l10n/gen
synthetic-package: true
nullable-getter: false
in my local, the above code is not an error. But when I run the project, I got this error.
Error: Couldn't resolve the package 'flutter_gen' in 'package:flutter_gen/gen_l10n/app_localizations.dart'.
I know that PhraseLocalizations
and AppLocalizations
it's from flutter_gen, I saw ur example as well. But the diff is in your example can run the project but in my side cant, do I miss some setup?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.