ilteoood / flutter_i18n

I18n made easy, for Flutter!
MIT License
217 stars 57 forks source link

No JSON file seems to be retrieving from NetworkFileTranslationLoader #189

Closed chamartt closed 2 years ago

chamartt commented 2 years ago

Hello,

I would like to use the NetworkFileTranslationLoader to retrieve my JSON files (like en.json, fr.json ...)

I configured the plugin as the exemple project, but no files seems to be retrieving, as I only have key.value (like loadings.app instead of 'App loading') text values in my app. With FileTranslationLoader, and the same files, it works well.

This is my code implementation :

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  final FlutterI18nDelegate flutterI18nDelegate = FlutterI18nDelegate(
      translationLoader: NetworkFileTranslationLoader(
    useCountryCode: false,
    fallbackFile: 'en',
    baseUri: Uri.https("lalgodepaulo.com", "translations"),
  ) // NOK

      // NetworkFileTranslationLoader(
      //   useCountryCode: false,
      //   fallbackFile: 'en',
      //   baseUri: Uri.https("l-algo-de-paulo-8fb41.appspot.com.storage.googleapis.com", "translations"),
      // ) NOK
      // FileTranslationLoader(useCountryCode: false, fallbackFile: 'en', basePath: 'assets/i18n'), OK
      );

  runApp(Test(flutterI18nDelegate));
}

class Test extends StatefulWidget {
  final FlutterI18nDelegate flutterI18nDelegate;

  Test(this.flutterI18nDelegate);

  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: (BuildContext context, Widget? child) {
        return MediaQuery(
          data: MediaQuery.of(context).copyWith(
            textScaleFactor: 1.0,
          ),
          child: child as Widget,
        );
      },
      title: 'TEST',
      home: myPage(),
      localizationsDelegates: [
        widget.flutterI18nDelegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
    );
  }
}

I looked for some log trace but I didn't find them.

Can you help to explain me/debug my implementation please ?

Thank you in advance !

ilteoood commented 2 years ago

This should have been fixed with the latest release

chamartt commented 2 years ago

Hi @ilteoood ,

Thank you for the update and your works.

This is the debug log when I try to specify your latest version 0.32.1 :

Because every version of flutter from sdk depends on meta 1.3.0 and toml >=0.12.0 depends on meta ^1.7.0, flutter from sdk is incompatible with toml >=0.12.0.

And because flutter_i18n >=0.31.1 depends on toml ^0.12.0, flutter from sdk is incompatible with flutter_i18n >=0.31.1.

So, because XXXX depends on both flutter any from sdk and flutter_i18n ^0.32.1, version solving failed.
pub get failed (1; So, because XXXX depends on both flutter any from sdk and flutter_i18n ^0.32.1, version solving failed.)

Do you know how can I workaround this please ?

Thank you again !

chamartt commented 2 years ago

When I try to download your package to override toml version, and run flutter pub get, this the trace error :

Because http 0.13.4 requires SDK version >=2.14.0 <3.0.0 and no versions of http match >0.13.4 <0.14.0, http ^0.13.4 is forbidden.

So, because flutter_i18n depends on http ^0.13.4, version solving failed.
pub get failed (1; So, because flutter_i18n depends on http ^0.13.4, version solving failed.)
exit code 1

I use Flutter version 2.2.3 and Dart SDK version 2.13.4.

Thank you in advance.

chamartt commented 2 years ago

Hi @ilteoood ,

Upgrading Flutter to 2.10.3 allows me to update all necessary plugins. Now NetworkFileTranslationLoader works well.

Thank you!