mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Make API settable in the command line as system property
git-svn-id: https://zxing.googlecode.com/svn/trunk@2706 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
a47790e2c9
commit
90ba467f47
|
@ -49,11 +49,13 @@ import java.util.regex.Pattern;
|
|||
* who should be forced to retranslate.
|
||||
* Usage: {@code StringsResourceTranslator android/res/ [key_1 ...]}</p>
|
||||
*
|
||||
* <p>You must set your Google Translate API key into the environment with -DtranslateAPI.key=...</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class StringsResourceTranslator {
|
||||
|
||||
private static final String API_KEY = "INSERT-YOUR-KEY";
|
||||
private static final String API_KEY = System.getProperty("translateAPI.key");
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
private static final Pattern ENTRY_PATTERN = Pattern.compile("<string name=\"([^\"]+)\".*>([^<]+)</string>");
|
||||
|
@ -183,6 +185,10 @@ public final class StringsResourceTranslator {
|
|||
}
|
||||
System.out.println(" Need translation for " + english);
|
||||
|
||||
if (API_KEY == null) {
|
||||
throw new IllegalArgumentException("translateAPI.key is not specified");
|
||||
}
|
||||
|
||||
URL translateURL = new URL(
|
||||
"https://www.googleapis.com/language/translate/v2?key=" + API_KEY + "&q=" +
|
||||
URLEncoder.encode(english, "UTF-8") +
|
||||
|
|
Loading…
Reference in a new issue