पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

GitHub रिपॉज़िटरीAkoWu101/gen_lang

gen_lang

gen_lang एक डार्ट पुस्तकालय है अंतर्राष्ट्रीय भाषा के लिए। यह Intl द्वारा आवश्यक डार्ट फ़ाइलें उत्पन्न करने के लिए संदेशों को निकालता है, Intl_translation और Flutter i18n से प्रेरित है

gen_lang प्रोजेक्ट कवर
स्टार
99
फ़ोर्क
25
अंतिम पुश (UTC)
13 अक्टू॰ 2022
प्रोजेक्ट स्थिति
सक्रिय

मूल README

यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।

gen_lang

gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl.

Now, three steps for internationalization

  1. Preparing Json files
  2. Run gen_lang
  3. Use it in coding

Installation

Add these libraries into pubspec.yaml

dependencies: 
    flutter_localizations: 
        sdk: flutter 
dev_dependencies:
    gen_lang: 0.1.3

Usage

pub run gen_lang:generate

A below table shown all supported arguments:

Argument Description
--source-dir A source folder contains all string json files (defaults to "res/string")
--output-dir A output folder stores all generated files (defaults to "lib/generated")
--template-locale Use string_{template-locale}.json as a template to search KEY. If string_en does not exist, this script will use the first string json file as a template (defaults to "en")

Source of Json Files

By default, the json files are required to locate at res/string. Using --source-dir argument can change the default source path. These files must be named in this pattern string_{Locale}.json

Example of the files,

|--- lib 
|--- res 
     |--- string 
         |--- string_en.json 
         |--- string_zh_TW.json 
         |--- string_ja.json 

Supported Message Type

Simple message

Define a json key and message without parameters

{ 
    "simpleMessage": "This is a simple Message"
}
Message with parameters

Define a message with parameters. Use ${parameterName} in a message.

{
    "messageWithParams": "Hi ${yourName}, Welcome you!"
}
Plural messages with parameters

Define messages in a plural form. ${how many} is a reserved parameter in a plural message. This parameters support integer only. For Intl, Intl.plural() supports these plural keyword including 'Zero', 'One', 'Two', 'Few', 'Many' and 'Other'. Define a json key into this pattern {jsonKey} {pluralKeyword}. For 'Other', need to define 'POther' for the plural keyword.

Example

{ 
    "pluralMessageZero": "Hi ${interviewerName}, I have no working experience.", 
    "pluralMessageOne": "Hi ${interviewerName}, I have one year working experience.", 
    "pluralMessageTwo": "Hi ${interviewerName}, I have two years of working experience.", 
    "pluralMessageFew": "Hi ${interviewerName}, I have few years of working experience.", 
    "pluralMessageMany": "Hi ${interviewerName}, I worked for a long time.", 
    "pluralMessagePOther": "Hi ${interviewerName}, I have ${howMany} years of working experience."
}

To know plural rules more, please read Intl's plural rules source code.

Gender message with parameters

Define a message in gender form. ${targetGender} is a reserved parameter in a gender message. This parameters support string value with 'male', female' and 'other'. For Intl, Intl.gender() supports these keyword including 'Male', 'Female' and 'Other'. Define a json key into this pattern {jsonKey} {genderKeyword}. For 'Other', need to define 'GOther' for the gender keyword.

Example

{ 
    "genderMessageMale": "Hi ${name}, He is boy.", 
    "genderMessageFemale": "Hi ${name}, She is girl", 
    "genderMessageGOther": "Hi ${name}, he/she is boy/girl." 
}

Usage of i18n.dart

The script will generate two files into the output folder including i18n.dart and messages_all.dart. Import i18n.dart into your source code. Then finish internationalization tasks.

Example

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

...

MaterialApp(
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      supportedLocales: S.delegate.supportedLocales,
      
      ...
      ...

        S.of(context).simpleMessage; // Simple Message 
        S.of(context).messageWithParams('developer'); // Message with parameters
        S.of(context).pluralMessage(10, 'King Wu'); // Plural Message with parameters
        S.of(context).genderMessage('male', 'King Wu'); // Gender Message with parameters
Running Script in Example

Go into example folder. Run the command

cd example
pub run gen_lang:generate

Then will generate i18n.dart and messages_all.dart

Powered By

Ako101 GitHub avatar
GitHub लेखक

Ako101 ↗

Product Owner | UX Design | Flutter | Android | Nodejs | VueJS | ReactJS | AngularJS | Unity

Wenjetso 搵著數 | PlakerLab 創玩坊Hong Kongआधिकारिक वेबसाइट ↗
भाषाएँDartRubySwiftKotlinObjective-C

श्रेणियाँ

उपयोग की गई निर्भरताएँ

निर्भरता सूची 3 आइटम

अपने प्रोजेक्ट के लिए रिपॉज़िटरी कैसे चुनें?

उपयोग के अनुसार छाँटें, गतिविधि की तुलना करें और अपनाने से पहले मूल प्रोजेक्ट की आवश्यकताएँ जाँचें।

  1. नाम, लेखक या विवरण से खोजें और तकनीकी विषय से परिणाम सीमित करें।
  2. स्टार, फ़ोर्क और हाल के पुश की तुलना करें। स्टार रुचि दर्शाते हैं, गुणवत्ता की गारंटी नहीं।
  3. उपयोग से पहले GitHub पर README, लाइसेंस और Issues जाँचें।

स्रोत और रखरखाव

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗