Giter Site home page Giter Site logo

kingwu / gen_lang Goto Github PK

View Code? Open in Web Editor NEW
100.0 100.0 24.0 85 KB

gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl, inspired by Intl_translation and Flutter i18n

License: BSD 2-Clause "Simplified" License

Dart 92.72% Kotlin 0.82% Ruby 5.39% Swift 0.97% Objective-C 0.09%
dart dart-library dartlang flutter flutter-package flutter-plugin flutter-plugins

gen_lang's People

Contributors

areille avatar kingwu avatar magtuxgit avatar maherjaafar avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gen_lang's Issues

The value 'null' can't be assigned to the parameter type 'I18nOption' because 'I18nOption' is not nullable.

Hello,

Getting the following error when trying to run flutter pub run gen_lang:generate

Failed to precompile gen_lang:generate:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:gen_lang
 - package:ansicolor

For solutions, see https://dart.dev/go/unsound-null-safety
/c:/flutter/.pub-cache/hosted/pub.dartlang.org/gen_lang-0.1.3/bin/generate.dart:17:35: Error: The value 'null' can't be assigned to the p
arameter type 'I18nOption' because 'I18nOption' is not nullable.
 - 'I18nOption' is from 'package:gen_lang/core_18n.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/gen_lang-0.1.3/lib/core_18n.dar
t').
  var parser = _generateArgParser(null);
                                  ^
pub finished with exit code 1

Running flutter pub run --no-sound-null-safety gen_lang:generate still gives the same error:

/c:/flutter/.pub-cache/hosted/pub.dartlang.org/gen_lang-0.1.3/bin/generate.dart:17:35: Error: The value 'null' can't be assigned to the p
arameter type 'I18nOption' because 'I18nOption' is not nullable.
 - 'I18nOption' is from 'package:gen_lang/core_18n.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/gen_lang-0.1.3/lib/core_18n.dar
t').
  var parser = _generateArgParser(null);
                                  ^
pub finished with exit code 254

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, 1.27.0-4.0.pre, on Microsoft Windows [Version 10.0.19042.804], locale en-AU)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] Connected device (3 available)

• No issues found!

Thanks!
Damian

Fixed sort

Hello.

There is some issue with random sort order of locales in generated files (i18n.dart and messages_all.dart).
Maybe platform related.
For example:
i18n.dart on Max OS:
return const [
Locale("en", ""),
Locale("uk", ""),
Locale("pl", ""),
Locale("ru", ""),
];
On Ubuntu:
return const [
Locale("en", ""),
Locale("ru", ""),
Locale("pl", ""),
Locale("uk", ""),
];

messages_all.dart - even worse.
We want this files to be included in git, instead of regenerate them each time we run build. So it would be great if sort could be fixed.

Translation issue with quote

Declaring a string that contains ' (for example l'aggiornamento) the resulting generation will contains double quotes.

Futhermore if you insert a \n the resulting string will be broken because in the generated file the \n breaks the line (it's not kept inside the text) and the string it's splitted into 2 strings and this results in a broken file that cannot be compiled

Possible solution: use double quote when initialize the string object in the generated file

Avoid using braces in interpolation when not needed

Hello,

I am using last version of this package alongside with dart 2.6.1 :

dart --version output:

Dart VM version: 2.6.1 (Mon Nov 11 13:12:24 2019 +0100) on "macos_x64"

On VSCode, dart linter shows these infos on gen_lang generated files :

Screen Shot 2019-12-02 at 11 07 25

It concerns mostly messages with parameters :

String yearsAgo(val) {
    return Intl.message("${val} years ago", name: 'yearsAgo', args: [val]);
}

This is the link to Dart language specs about string interpolation.

Thanks

Build Errors in Null Safety Project Dart 2.13

generated files not working anymore.

is there a way to bring the gen_lang package to the current versions?

lib/generated/i18n.dart:4126:55: Error: The parameter 'fallback' can't have a value of 'null' because of its type 'Locale', but the implicit default value is 'null'.
 - 'Locale' is from 'dart:ui'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
  LocaleListResolutionCallback listResolution({Locale fallback}) { 

lib/generated/i18n.dart:15:26: Error: A value of type 'S?' can't be returned from a function with return type 'S' because 'S?' is nullable and 'S' isn't.


lib/generated/i18n.dart:4129:16: Warning: Operand of null-aware operation '??' has type 'Locale' which excludes null.
 - 'Locale' is from 'dart:ui'.

lib/generated/i18n.dart:4127:12: Error: A value of type 'Locale Function(List<Locale>, Iterable<Locale>)' can't be returned from a function with return type 'Locale? Function(List<Locale>?, Iterable<Locale>)' because 'List<Locale>?' is nullable and 'List<Locale>' isn't.
 - 'Locale' is from 'dart:ui'.
 - 'List' is from 'dart:core'.
 - 'Iterable' is from 'dart:core'.
    return (List<Locale> locales, Iterable<Locale> supported) {
lib/generated/messages_all.dart:1049:14: Error: The value 'null' can't be returned from a function with return type 'MessageLookupByLibrary' because 'MessageLookupByLibrary' is not nullable.
 - 'MessageLookupByLibrary' is from 'package:intl/message_lookup_by_library.dart' 

Upgrade args Package

after upgrading to Flutter 2.0 and update some package to be compatible with Flutter 2.0, i got this issue:

Because flutter_launcher_icons >=0.9.0 depends on args 2.0.0 and gen_lang 0.1.3 depends on args >=0.12.1 <2.0.0, flutter_launcher_icons >=0.9.0 is incompatible with gen_lang 0.1.3.

And because no versions of gen_lang match >0.1.3 <0.2.0, flutter_launcher_icons >=0.9.0 is incompatible with gen_lang ^0.1.3.

can you upgrade the args package?

Feature request: commenting

When you deal with hundreds of strings, it's very useful to be able to organize them in blocks with comments. However, commenting inside Json is not supported. The IDE gives me the message "Use JSMin or similar tools to remove comments before parsing". Can something be done to support this?

Version solving failed with firebase packages

I have encountered this issue when I try using one of the following packages

firebase_crashlytics: ^2.4.4
firebase_messaging: ^11.2.4
firebase_core: ^1.10.66
flutter_local_notifications: ^9.1.5

with gen_lang: ^0.1.3
Issue seems to be related with args, cause of this log when I run flutter pub get :

Because no versions of gen_lang match >0.1.3 <0.2.0 and gen_lang 0.1.3 depends on args >=0.12.1 <2.0.0, gen_lang ^0.1.3 requires args >=0.12.1 <2.0.0.
And because dbus >=0.2.0 depends on args ^2.0.0, gen_lang ^0.1.3 is incompatible with dbus >=0.2.0.
And because flutter_local_notifications >=9.1.5 <10.0.0-dev.1 depends on flutter_local_notifications_linux ^0.4.0 which depends on dbus ^0.6.0, gen_lang ^0.1.3 is incompatible with flutter_local_notifications >=9.1.5 <10.0.0-dev.1.

Is there any planned update for this? Or am I missing anything!?

Support for nested JSON properties

Hi!

It would be nice to be able to put nested objects in the JSON file to sort properties by more intuitive groups rather than separating them by a prefix.

Best way to get all strings and save it in array?

Hi.

  1. What would be the best way to get all the strings and save them in array? So I could use it in ListView?

  2. Is it possible to "categorize" strings inside string_en.json file? Or if not, what would be the best logic to save into array just strings that starts with card_category1_?

{
  "card_category1_test": "test",
  "card_category1_abc": "abc",
  "card_category2_test": "Another test",
  "card_category2_abc": "Another abc"
}

Next line separator while generating text with \n

Hi, I need to have need paragraph in my string line, so I'm writing :

'Firstly enter your email and password.\nThis is not difficult )'

but it's generated as

'Firstly enter your email and password.
This is not difficult )'

it's not difficult to correct it every time, but if it'll be more then 100 strings with same format, it's gonna to be a trouble

Intelij Usage: pub run gen_lang:generate fails

Hello,
Every time I run Intleij it empties out the i18n.dart file with the messages I have defined. Is there any way to resolve this? I have tried removing the gen_lang dependencies in the pubspec after I run pub run gen_lang:generate and before I open Intelij and the issue still persists.

Improvement idea: support object grouping

We've been using this package to manage our texts and really love the plural functions. The only problem I see is organizing your text definition. It's not an issue when you have only a few lines in your JSON file but as the projects gets bigger with more areas and topics in the app, it gets harder to stay organized.

As JSON doesn't allow comments, my idea would be to create objects in the definition itself and have texts in it. For instance:

{
    "screenSharing": {
        "title": "Screen sharing",
        "startError": "Another user is already sharing his screen."
    }
}

instead of:

{
    "screenSharing_title": "Screen sharing",
    "screenSharing_startError": "Another user is already sharing his screen."
}

That would make things so much easier to maintain. Hope this idea gets through!

error when try to run the app

Launching lib/config/main_production.dart on Android SDK built for x86 64 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleProductionDebug'...

Compiler message:
file:///Users/shiv/apps/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_stetho-0.2.2/lib/src/http_client_response.dart:4:7: Error: The non-abstract class 'StethoHttpClientResponse' is missing implementations for these members:
 - HttpClientResponse.compressionState
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class StethoHttpClientResponse extends StreamView<List<int>>
      ^^^^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///third_party/dart/sdk/lib/_http/http.dart:1967:42: Context: 'HttpClientResponse.compressionState' is defined here.
  HttpClientResponseCompressionState get compressionState;
                                         ^^^^^^^^^^^^^^^^
Compiler failed on /Users/shiv/projects/ex/flutter_starter_kit/lib/config/main_production.dart

FAILURE: Build failed with an exception.

* Where:
Script '/Users/shiv/apps/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 665

* What went wrong:
Execution failed for task ':app:compileflutterBuildProductionDebugX64'.
> Process 'command '/Users/shiv/apps/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s
Finished with error: Gradle task assembleProductionDebug failed with exit code 1

allow multiple parameters

I really love this package and would like to use it instead of my own hand-rolled solution, but I need to be able to pass in multiple parameters for some messages. Would it be possible to add that as an option?

S.of(context) is null

import 'package:package_name/generated/i18n.dart';

I am trying to fetch the string using

S.of(context).intro_title_first,

but S.of(context) is null.

Strings are null at UI tests

Hi,
I'm building a UI test for my screen - and the test is failing when calling S.of(context).someText

The test:

void main(){
  testWidgets('Intro screen test', (WidgetTester tester) async {
    GetIt.instance.reset();
    locator.registerSingleton(KeyboardManager());

    await tester.pumpWidget(buildTestableWidget(IntroScreen()));
    await tester.pumpAndSettle();

    final buttonFinder = find.byType(IntroCtaButton);

    expect(buttonFinder, findsNWidgets(2));
  });
}

Widget buildTestableWidget(Widget widget) {
  return MediaQuery(
    data: const MediaQueryData(),
    child: MaterialApp(
      localizationsDelegates: const [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      supportedLocales: S.delegate.supportedLocales,
      home: widget,
    ),
  );
}

The error:
The getter 'someText' was called on null.

Seen some related issue like this and this medium article but couldn't get it working.

When I'm trying to set S.of(context).text to AppBar always en location

Location changes correctly but in application bar text always in en location

`class RegisterPage extends StatelessWidget {
final UserRepository userRepository;

RegisterPage({Key key, @required this.userRepository})
: assert(userRepository != null),
super(key: key);

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(S.of(context).app_bar_register),
),
body: BlocProvider(
create: (context) {
return RegisterBloc(
authenticationBloc: BlocProvider.of(context),
userRepository: userRepository,
);
},
child: RegisterForm(),
),
);
}
}`

Usage in BottomNavigationBarItem

Hello,

First thank you for the good library!

I'm facing an issue when trying to set a BottomNavigationBarItem Title.

BottomNavigationBarItem(
                icon: Icon(Icons.dialpad),
                title: new Text( S.of(context).example )
              )

It throws the following errors:

Invalid constant value.

The values in a const list literal must be constants.
Try removing the keyword 'const' from the list literal.

Arguments of a constant creation must be constant expressions.
Try making the argument a valid constant, or use 'new' to call the constructor

Using a simple string, such as Text('Test') it works.

Do you think it's possible to solve this issue?

Thank you!

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.