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

[🌎 Easy Localization] [WARNING] Localization key [updating] not found #717

Open
qiuweilu opened this issue Oct 18, 2024 · 1 comment
Open

Comments

@qiuweilu
Copy link

qiuweilu commented Oct 18, 2024

assets:

  • assets/translations/

WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();

import 'boot.dart';
import 'config/route_conf.dart';
import 'constant/app_const.dart';
import 'constant/sys_const.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:device_preview/device_preview.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

bool devicePreview = false;

///QWL v2.1
void main() {
  Boot.init().then(
    (value) => runApp(
      EasyLocalization(
        path: SysConst.translationsDir,
        fallbackLocale: Locale('en'),
        supportedLocales: [Locale('en'), Locale('zh')],
        child: devicePreview
            ? DevicePreview(
                enabled: !kReleaseMode,
                builder: (context) => const ProviderScope(child: MyApp()),
              )
            : const ProviderScope(child: MyApp()),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      minTextAdapt: true,
      splitScreenMode: true,
      designSize: Size(SysConst.width, SysConst.height),
      builder: (_, child) {
        return MaterialApp.router(
          locale: context.locale,
          theme: AppConst.whiteThemeData,
          debugShowCheckedModeBanner: false,
          routerConfig: RouteConf.routerConfig,
          supportedLocales: context.supportedLocales,
          localizationsDelegates: context.localizationDelegates,
        );
      },
    );
  }
}

All the above code is correct, but I introduced easy_localization in the FileUtil utility class and directly used tr("updating") or "updating".tr(), and it reported an error as shown in the title.

import 'package:easy_localization/easy_localization.dart';
class FileUtil {
    static Future<void> updateApp(String downloadUrl) async {
        .... tr("updating") .....
    }
}
@qiuweilu
Copy link
Author

easy_localization: ^3.0.7

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

No branches or pull requests

1 participant