Get Translations Generator

Installation CLI

dart pub global activate get_translations_generator

Run CLI

dart pub global run get_translations_generator <CSV file path> <output Dart file path>

Example CLI

dart pub global run get_translations_generator input.csv output.dart

Example file csv for generate translations

th_TH,greetings,สวัสดี
en_US,greetings,hello
th_TH,search,ค้นหา
en_US,search,search

Example Result file get transaltions

import 'package:get/get.dart'; 

class Translate extends Translations {
  @override
  Map<String, Map<String, String>> get keys => {
    'th_TH': {
      'greetings': 'สวัสดี',
      'search': 'ค้นหา',
      'weather': 'สภาพอากาศ',
    },
    'en_US': {
      'greetings': 'hello',
      'search': 'search',
      'weather': 'weather',
    },
  };
}


class TranslateKeys {
    static const String greetings = 'greetings';
    static const String search = 'search';
    static const String weather = 'weather';
} 

Example Usecases

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

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Example App',
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('en', 'US'), // English
        Locale('th', 'TH'), // Thai
      ],
      locale: const Locale('en', 'US'),
      translations: Translate(),
      home: Example(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Example'),
      ),
      body: Center(
        child: Text(TranslateKeys.greetings.tr),
      ),
    );
  }
}

Libraries