FLUTTER ECOSYSTEM

melodysdreamj/auto_app_translate

melodysdreamj/auto_app_translate open-source repository details.

auto_app_translate 專案封面
Stars
5
Forks
3
最近推送(UTC)
2023年12月3日
專案狀態
未封存
june lee GitHub avatar
GITHUB User

june lee ↗

A developer in Songdo who loves cafes and good restaurants.

語言DartRubySwiftKotlinObjective-C

此儲存庫發佈的套件

使用的依賴

依賴清單 9 項

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

展開 / 收合專案 README

Auto App Translate

Pub

It is a library that translates apps into 80 languages and automates settings.

https://user-images.githubusercontent.com/21379657/205305607-951f2eb9-700a-418d-a276-2927e158e9c8.jpg

"Buy Me A Coffee"

How to Use?

1. Setup the config file
dependencies:
  easy_localization: ^3.0.3
  easy_localization_loader: ^2.0.0
  auto_app_translate:
  
flutter:
  assets:
    - assets/localization.csv
2. Create the asset folder and insert the localization.csv file.

https://user-images.githubusercontent.com/21379657/205302098-b05eaa27-3357-4aa1-8ee6-aa1cd8fde92c.png
lozalization.csv file download

3. Config easy_localization library. Please refer to the official documentation.
import 'package:auto_app_translate/callable/core_my/my_language_code/entity/flutter_support_language_locale.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:easy_localization_loader/easy_localization_loader.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  runApp(
    EasyLocalization(
        supportedLocales: flutterLocalizeSupportLanguagesLocale,
        path: 'assets/localization.csv',
        assetLoader: CsvAssetLoader(), // <- important option for translation
        fallbackLocale: const Locale('en', 'US'),
        child: MyApp()
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        localizationsDelegates: context.localizationDelegates,
        supportedLocales: context.supportedLocales,
        locale: context.locale,
        home: MyHomePage()
    );
  }
}
4. Fill in the localization file.

Fill in str for the key value and the standard language (start translate language) column. https://user-images.githubusercontent.com/21379657/205302110-bc47084e-dc24-4a6e-b9f6-2fed460de511.png

5. use tr() in your code for localization.

https://user-images.githubusercontent.com/21379657/205302122-601141a6-bee3-42cd-bd23-e4dcc85f8138.png

import 'package:easy_localization/easy_localization.dart';

tr('hello world')
6. Create a dart file in your project and paste the code below.

create auto_translation folder in your project root, and create auto_translation.dart file. and then copy paste code below.

import 'package:auto_app_translate/auto_app_translate.dart';

main() {
  AutoAppTranslate.translateAppCsvFile(
    // start translate language
    startLanguageCode: 'en',
    
    // language code to skip translation
    skipLanguageCodes: [],
    
    // str to skip translation
    skipStr: [],
    
    // csv file path
    appAssetsCsvPath: 'assets/localization.csv',
    
    // google translate api key (https://translatepress.com/docs/automatic-translation/generate-google-api-key/)
    apiKey: 'INPUT_YOUR_GOOGLE_TRANSLATE_API_KEY');
}

It works even if you don't put the Google Translate api key, but you will soon reach the free limit.
For a guide to getting the Google Translate api key, please refer to this document.

7. Run the file. The translation will be completed in the csv file.

https://user-images.githubusercontent.com/21379657/205302139-b8c667f7-1dd6-446d-bfab-048633935b92.png

8. Check out apps translated into more than 80 languages :)