中文说明文档 README_CN.md
- add gradle build system
- add Intellij idea ini file comments support
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}Step 2. Add the dependency
dependencies {
implementation 'com.github.onlynight:FastIni:1.2.1'
}To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>Step 2. Add the dependency
<dependency>
<groupId>com.github.onlynight</groupId>
<artifactId>FastIni</artifactId>
<version>1.2.1</version>
</dependency>This is a *.ini file parser java tools. It will help you parse .ini file quickly such as google's Gson.
I hava extention the .ini file, becourse the .ini file is the single key value types, so i change the value to the list, if you want some key with a list of value you can write like this:
key = value1,value2,value3The release fastini-x.x.x.jar file are in the root of /bin directory. You can download the fast-ini-x.x.x.jar lib, and add it in your project.
It is simple to use:
FastInifastIni = newFastIni();
Demodemo = fastIni.fromPath("the file path", Demo.class);or you dont want to get all property by template, you can use like this:
niDocumentdocument = newIniDocument("the file path").parse();
List<String> values = document.get("key");filename translate_config.ini
[platform key]# baidu translate api info, you should replace it with your own.baidu_app_id = 123413312312
baidu_app_secret = sadfwqeersddafasdftryyjghsaddarytre
# google translate api info, you should replace it with your own.google_api_key = qoiewtusdjifoiasjoteertqwerqwe
# youdao translate api info, you should replace it with your own.youdao_api_key = 32423512412
[platform]# now support google, baidu, youdao translate platform api.# the value you can choose are "google", "baidu", "youdao"translate_platform = google
[phone platform]# now support android .xml string res and ios .strings string res translate.# the value you can choose are "android" or "ios"phone_platform = android
[translator]# the source language you provided.source_language = zh-CN
# if you want translate all language you should use "all" to replace this value.# use "all" means you want translate the platform support all languages;# or you should use language code to tell the translate you want to translate.## the platform support language contains in the root of the project xxx_support_laguage.txt# you can check this file to get the platform support languagedestination_language = en,zh_TW
# the translate file must in the same path or sub dir of the translator.jar.# this value assign the folder name, if you don't want use sub dir,# just use "/" to replace the valuesource_file_path = valuespublicclassMain {
publicstaticvoidmain(String[] args) {
FastIniini = newFastIni();
FilecurrentPath = newFile("");
TestBeanbean = ini.fromPath(newFile(currentPath.getAbsolutePath(), "translate_config.ini").
getAbsolutePath(), TestBean.class);
System.out.println(bean);
}
publicstaticclassTestBean {
publicstaticfinalStringTAG = TestBean.class.getSimpleName();
privateStringappId;
privateStringappKey;
privateStringapiUrl;
privateList<String> others;
privateStringtranslatePlatform;
privateStringtextType;
privateStringsourceLanguage;
privateList<String> destinationLanguage;
privateStringsourceFilePath;
publicStringgetAppId() {
returnappId;
}
publicvoidsetAppId(StringappId) {
this.appId = appId;
}
publicStringgetAppKey() {
returnappKey;
}
publicvoidsetAppKey(StringappKey) {
this.appKey = appKey;
}
publicStringgetApiUrl() {
returnapiUrl;
}
publicvoidsetApiUrl(StringapiUrl) {
this.apiUrl = apiUrl;
}
publicList<String> getOthers() {
returnothers;
}
publicvoidsetOthers(List<String> others) {
this.others = others;
}
publicStringgetTranslatePlatform() {
returntranslatePlatform;
}
publicvoidsetTranslatePlatform(StringtranslatePlatform) {
this.translatePlatform = translatePlatform;
}
publicStringgetTextType() {
returntextType;
}
publicvoidsetTextType(StringtextType) {
this.textType = textType;
}
publicStringgetSourceLanguage() {
returnsourceLanguage;
}
publicvoidsetSourceLanguage(StringsourceLanguage) {
this.sourceLanguage = sourceLanguage;
}
publicList<String> getDestinationLanguage() {
returndestinationLanguage;
}
publicvoidsetDestinationLanguage(List<String> destinationLanguage) {
this.destinationLanguage = destinationLanguage;
}
publicStringgetSourceFilePath() {
returnsourceFilePath;
}
publicvoidsetSourceFilePath(StringsourceFilePath) {
this.sourceFilePath = sourceFilePath;
}
@OverridepublicStringtoString() {
StringBuilderlanguages = newStringBuilder();
try {
for (Stringlang : destinationLanguage) {
languages.append(lang).append(",");
}
languages.deleteCharAt(languages.length() - 1);
} catch (Exceptione) {
e.printStackTrace();
}
return"appId" + " = " + appId + "\n" +
"appKey" + " = " + appKey + "\n" +
"apiUrl" + " = " + apiUrl + "\n" +
"others" + " = " + list2String(others) + "\n" +
"translatePlatform" + " = " + translatePlatform + "\n" +
"textType" + " = " + textType + "\n" +
"sourceLanguage" + " = " + sourceLanguage + "\n" +
"destinationLanguage" + " = " + list2String(destinationLanguage) + "\n" +
"sourceFilePath" + " = " + sourceFilePath + "\n";
}
privatestaticStringlist2String(List<String> list) {
StringBuilderlanguages = newStringBuilder();
if (list != null) {
try {
for (Stringdata : list) {
languages.append(data).append(",");
}
languages.deleteCharAt(languages.length() - 1);
} catch (Exceptione) {
e.printStackTrace();
}
}
returnlanguages.toString();
}
}
}@TestpublicvoidtestParseDoc() {
StringfilePath = newFile(newFile("").getAbsoluteFile(),
"translate_config.ini").getAbsolutePath();
IniDocumentdocument = newIniDocument().fromPath(filePath);
List<String> languages = document.get("destinationLanguage");
if (languages != null) {
for (Stringlang : languages) {
System.out.println(lang);
}
}
System.out.println(document.get("appKey").get(0));
}Copyright 2017 onlynight
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.