Code Monkey home page Code Monkey logo

flutter_sdk_example's People

Contributors

darkminstrel avatar felixssimoes avatar thesoenke avatar vermaxik avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_sdk_example's Issues

Feature Request : Translating a String variable

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);

chore(deps): please update `package_info_plus` constraints

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.

fix: consider `l10n.yaml`'s `output-class` parameter when generating `PhraseLocalizations` class

Summary

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.

Problem

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.

Proposal

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

Problem with generating builds

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

Locally
Screenshot 2022-12-06 at 13 20 13

main.dart

    ...
    localizationsDelegates: PhraseLocalizations.localizationsDelegates,
    supportedLocales: PhraseLocalizations.supportedLocales,
    ...

Placeholders not generated in .arb files for plural forms

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 :)

Phrase.getText() not work.

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

Modified generated code

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:

  • hard to get localization because always needed a context (u can see first example code above) and also not testable coz of a context.
  • every I generated new phrase, my modified code always replaced

Feature request (Flutter): Deleting the cache on the local device

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.

Update of the dependencies

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 ?

bug: `Error: The class 'FileSystemEvent' can't be extended [...] in outside of its library because it's a sealed class.`

Summary

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 ๐Ÿ˜ƒ

failed to run because of flutter_gen

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.