1. Set up all strings in res/*/strings.xml rather than as string

literals.
2. Using a very handy script for this purpose, and checking it
   into utils/ since it saved me some headache.
3. Turned tabs -> spaces for WifiResultHandler.
4. Better error handling on network types: look for exact matches
   rather than substrings.



git-svn-id: https://zxing.googlecode.com/svn/trunk@1456 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
vikrama 2010-06-23 06:00:57 +00:00
parent c2e3604aea
commit c003d96b89
21 changed files with 218 additions and 65 deletions

View file

@ -121,5 +121,10 @@
<string name="share_name">مشاركة عبر الرمز الشريطي</string>
<string name="title_about">إصدار ماسح الرمز الشريطي</string>
<string name="wa_name">التكوين اللاسلك</string>
<string name="wifi_changing_network">تغيير الشبكة</string>
<string name="wifi_creating_network">إنشاء شبكة</string>
<string name="wifi_modifying_network">تعديل شبكة</string>
<string name="wifi_ssid_missing">اسم الشبكة مفقود</string>
<string name="wifi_type_incorrect">شبكة نوع غير صحيح</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Sdílet pomocí čárového kódu</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Bezdrátová konfigurace</string>
<string name="wifi_changing_network">Změna síť</string>
<string name="wifi_creating_network">Vytvoření sítě</string>
<string name="wifi_modifying_network">Úprava sítě</string>
<string name="wifi_ssid_missing">Název sítě chybí</string>
<string name="wifi_type_incorrect">Typ sítě nesprávné</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Del via stregkode</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Wifi-forbindelse</string>
<string name="wifi_changing_network">Ændring Network</string>
<string name="wifi_creating_network">Oprettelse af netværk</string>
<string name="wifi_modifying_network">Ændring Network</string>
<string name="wifi_ssid_missing">Netværk navn mangler</string>
<string name="wifi_type_incorrect">Netværk type forkert</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>
</resources>

View file

@ -122,4 +122,9 @@
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Wifi konfiguration</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
<string name="wifi_changing_network">Ändern der Netzwerkeinstellungen</string>
<string name="wifi_creating_network">Erstellen Network</string>
<string name="wifi_modifying_network">Ändern Network</string>
<string name="wifi_ssid_missing">Netzwerk-Name fehlt</string>
<string name="wifi_type_incorrect">Netzwerk-Typ nicht korrekt</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Compartir por códigos de barras</string>
<string name="title_about">Escáner de código de barras v</string>
<string name="wa_name">Configuración de la red</string>
<string name="wifi_changing_network">Cambio de la red</string>
<string name="wifi_creating_network">Creación de la Red</string>
<string name="wifi_modifying_network">Modificación de la Red</string>
<string name="wifi_ssid_missing">Nombre de la red desaparecidas</string>
<string name="wifi_type_incorrect">Red de tipo incorrecto</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Jaa viivakoodilla</string>
<string name="title_about">Viivakoodin lukija v</string>
<string name="wa_name">Langattoman yhteyden</string>
<string name="wifi_changing_network">Vaihtaminen Verkko</string>
<string name="wifi_creating_network">Luominen verkoston</string>
<string name="wifi_modifying_network">Muuttaminen Verkko</string>
<string name="wifi_ssid_missing">Verkon nimi puuttuu</string>
<string name="wifi_type_incorrect">Verkon tyyppi virheellinen</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Partager par code barre</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Configuration du réseau</string>
<string name="wifi_changing_network">Changement de réseau</string>
<string name="wifi_creating_network">Création d\u0026#39;un réseau</string>
<string name="wifi_modifying_network">Modification du réseau</string>
<string name="wifi_ssid_missing">Le nom du réseau disparus</string>
<string name="wifi_type_incorrect">Réseau de type incorrect</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Megosztás vonalkóddal</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Hálózati konfiguráció</string>
<string name="wifi_changing_network">Változó Hálózat</string>
<string name="wifi_creating_network">Hálózat létrehozása</string>
<string name="wifi_modifying_network">Módosítása Hálózat</string>
<string name="wifi_ssid_missing">A hálózat neve hiányzik</string>
<string name="wifi_type_incorrect">Hálózati típusú hibás</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Condividi tramite codice a barre</string>
<string name="title_about">Scansione codice a barre v</string>
<string name="wa_name">Configurazione di rete</string>
<string name="wifi_changing_network">Cambiare Network</string>
<string name="wifi_creating_network">Creazione di rete</string>
<string name="wifi_modifying_network">Modifica della rete</string>
<string name="wifi_ssid_missing">Nome della rete mancante</string>
<string name="wifi_type_incorrect">Tipo di rete non corretto</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">バーコードで共有する</string>
<string name="title_about">>QRコードスキャナー v</string>
<string name="wa_name">ネットワーク構成</string>
<string name="wifi_changing_network">ネットワークを変更する</string>
<string name="wifi_creating_network">作成ネットワーク</string>
<string name="wifi_modifying_network">ネットワークを変更する</string>
<string name="wifi_ssid_missing">ネットワーク名を欠いて</string>
<string name="wifi_type_incorrect">ネットワーク型不正</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Deel via barcode</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Netwerkconfiguratie</string>
<string name="wifi_changing_network">Veranderen van Netwerk</string>
<string name="wifi_creating_network">Creating Network</string>
<string name="wifi_modifying_network">Het wijzigen van Netwerk</string>
<string name="wifi_ssid_missing">Netwerk naam ontbreekt</string>
<string name="wifi_type_incorrect">Netwerk soort onjuiste</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Udostępnij przez kod paskowy</string>
<string name="title_about">Skaner Kodów Paskowych v</string>
<string name="wa_name">Konfiguracja sieci</string>
<string name="wifi_changing_network">Zmiana sieci</string>
<string name="wifi_creating_network">Tworzenie sieci</string>
<string name="wifi_modifying_network">Modyfikowanie sieci</string>
<string name="wifi_ssid_missing">Nazwa sieci brakuje</string>
<string name="wifi_type_incorrect">Typ sieci nieprawidłowe</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Partilhar por código de barras</string>
<string name="title_about">Scanner de código barras v</string>
<string name="wa_name">Configuração de rede</string>
<string name="wifi_changing_network">Mudar Rede</string>
<string name="wifi_creating_network">Criação da rede</string>
<string name="wifi_modifying_network">Modificando Rede</string>
<string name="wifi_ssid_missing">Nome da rede em falta</string>
<string name="wifi_type_incorrect">Rede de tipo incorreto</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Поделиться через штрих-код</string>
<string name="title_about">Сканер штрих-кодов версии </string>
<string name="wa_name">конфигурации сети</string>
<string name="wifi_changing_network">Изменение сети</string>
<string name="wifi_creating_network">Создание сети</string>
<string name="wifi_modifying_network">Изменение сети</string>
<string name="wifi_ssid_missing">Сеть отсутствует имя</string>
<string name="wifi_type_incorrect">Тип сети неправильный</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Dela via streckkod</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Nätverkskonfiguration</string>
<string name="wifi_changing_network">Ändra Network</string>
<string name="wifi_creating_network">Skapa nätverk</string>
<string name="wifi_modifying_network">Modifiera nätverk</string>
<string name="wifi_ssid_missing">Nätverksnamn saknas</string>
<string name="wifi_type_incorrect">Nätverkstyp felaktig</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">通过条码分享</string>
<string name="title_about">条码扫描器</string>
<string name="wa_name">网络配置</string>
<string name="wifi_changing_network">不断变化的网络</string>
<string name="wifi_creating_network">创建网络</string>
<string name="wifi_modifying_network">修改网络</string>
<string name="wifi_ssid_missing">网络实名失踪</string>
<string name="wifi_type_incorrect">网络类型不正确</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">通過條碼分享</string>
<string name="title_about">條碼掃描器</string>
<string name="wa_name">網絡配置</string>
<string name="wifi_changing_network">不斷變化的網絡</string>
<string name="wifi_creating_network">創建網絡</string>
<string name="wifi_modifying_network">修改網絡</string>
<string name="wifi_ssid_missing">網絡實名失踪</string>
<string name="wifi_type_incorrect">網絡類型不正確</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -121,5 +121,10 @@
<string name="share_name">Share via barcode</string>
<string name="title_about">Barcode Scanner v</string>
<string name="wa_name">Wifi Connection</string>
<string name="wifi_changing_network">Changing Network</string>
<string name="wifi_creating_network">Creating Network</string>
<string name="wifi_modifying_network">Modifying Network</string>
<string name="wifi_ssid_missing">Network name missing</string>
<string name="wifi_type_incorrect">Network type incorrect</string>
<string name="zxing_url">http://code.google.com/p/zxing</string>
</resources>

View file

@ -28,53 +28,53 @@ import com.google.zxing.client.result.WifiParsedResult;
* @author viki@google.com (Vikram Aggarwal)
*/
public final class WifiResultHandler extends ResultHandler {
Activity parentActivity = null;
public WifiResultHandler(Activity activity, ParsedResult result) {
super(activity, result);
parentActivity = activity;
}
Activity parentActivity = null;
public WifiResultHandler(Activity activity, ParsedResult result) {
super(activity, result);
parentActivity = activity;
}
@Override
public int getButtonCount() {
// We just need one button, and that is to configure the wireless. This could change in the future.
return 1;
}
@Override
public int getButtonCount() {
// We just need one button, and that is to configure the wireless. This could change in the future.
return 1;
}
@Override
public int getButtonText(int index) {
switch (index) {
case 0:
return R.string.button_wifi;
default:
throw new ArrayIndexOutOfBoundsException();
}
}
@Override
public int getButtonText(int index) {
switch (index) {
case 0:
return R.string.button_wifi;
default:
throw new ArrayIndexOutOfBoundsException();
}
}
@Override
public void handleButtonPress(int index) {
// Get the underlying wifi config
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
switch (index) {
case 0:
wifiConnect(wifiResult);
break;
default:
break;
}
}
@Override
public void handleButtonPress(int index) {
// Get the underlying wifi config
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
switch (index) {
case 0:
wifiConnect(wifiResult);
break;
default:
break;
}
}
// Display the name of the network and the network type to the user.
@Override
public CharSequence getDisplayContents() {
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
StringBuffer contents = new StringBuffer();
ParsedResult.maybeAppend(wifiResult.getSsid(), contents);
ParsedResult.maybeAppend(wifiResult.getNetworkEncryption(), contents);
return contents.toString();
}
// Display the name of the network and the network type to the user.
@Override
public CharSequence getDisplayContents() {
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
StringBuffer contents = new StringBuffer();
ParsedResult.maybeAppend(wifiResult.getSsid(), contents);
ParsedResult.maybeAppend(wifiResult.getNetworkEncryption(), contents);
return contents.toString();
}
@Override
public int getDisplayTitle() {
return R.string.result_wifi;
}
@Override
public int getDisplayTitle() {
return R.string.result_wifi;
}
}

View file

@ -39,11 +39,6 @@ import com.google.zxing.client.android.R;
*
* TODO(viki): Tell the user when the network is not available here
* TODO(viki): Incorrect password, could not connect, give an error
* TODO(viki): Should never crash: crashes on S:ssid;P:pass;T:something;else;
* TODO(viki):
* TODO(viki):
* TODO(viki):
* TODO(viki):
*
* @author Vikram Aggarwal
*/
@ -64,13 +59,13 @@ public class WifiActivity extends Activity {
// If the SSID is empty, throw an error and return
if (setting.getSsid() == null || setting.getSsid().length() == 0) {
return doError("SSID name missing");
return doError(R.string.wifi_ssid_missing);
}
// If the network type is invalid
if (setting.getNetworkType() == NetworkType.NETWORK_INVALID){
return doError("Network type incorrect");
return doError(R.string.wifi_type_incorrect);
}
// If the password is empty, this is an unencrypted network
if (setting.getPassword() == null || setting.getPassword().length() == 0 ||
setting.getNetworkType() == null ||
@ -78,14 +73,14 @@ public class WifiActivity extends Activity {
return changeNetworkUnEncrypted(setting);
}
if (setting.getNetworkType() == NetworkType.NETWORK_WPA) {
return changeNetworkWPA(setting);
return changeNetworkWPA(setting);
} else {
return changeNetworkWEP(setting);
}
}
private int doError(String string) {
statusView.setText(string);
private int doError(int resource_string) {
statusView.setText(resource_string);
return -1;
}
@ -101,13 +96,13 @@ public class WifiActivity extends Activity {
config.allowedProtocols.clear();
// Android API insists that an ascii SSID must be quoted to be correctly handled.
config.SSID = NetworkUtil.convertToQuotedString(input.getSsid());
config.SSID = NetworkUtil.convertToQuotedString(input.getSsid());
config.hiddenSSID = true;
return config;
}
private int requestNetworkChange(WifiConfiguration config){
statusView.setText("Changing Network...");
statusView.setText(R.string.wifi_changing_network);
return updateNetwork(config, false);
}
@ -184,15 +179,15 @@ public class WifiActivity extends Activity {
// TODO(vikrama): Error checking here, to ensure ssid exists.
NetworkType networkT;
if (networkType.contains("WPA")) {
if (networkType.equals("WPA")) {
networkT = NetworkType.NETWORK_WPA;
} else if (networkType.contains("WEP")) {
} else if (networkType.equals("WEP")) {
networkT = NetworkType.NETWORK_WEP;
} else if (networkType.contains("nopass")) {
networkT = NetworkType.NETWORK_NOPASS;
} else if (networkType.equals("nopass")) {
networkT = NetworkType.NETWORK_NOPASS;
} else {
// Got an incorrect network type. Give an error
doError("Incorrect Network type: " + networkType);
doError(R.string.wifi_type_incorrect);
return;
}
@ -229,10 +224,10 @@ public class WifiActivity extends Activity {
private int updateNetwork(WifiConfiguration config, boolean disableOthers){
int networkId;
if (findNetworkInExistingConfig(config.SSID) == null){
statusView.setText("Creating network...");
statusView.setText(R.string.wifi_creating_network);
networkId = wifiManager.addNetwork(config);
} else {
statusView.setText("Modifying network...");
statusView.setText(R.string.wifi_modifying_network);
networkId = wifiManager.updateNetwork(config);
}
if (networkId == -1 || !wifiManager.enableNetwork(networkId, disableOthers)) {

68
android/utils/translate.py Executable file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env python
#
# Copyright (C) 2010 ZXing authors
#
# 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.
# Translate a string from English to all locales used in the Barcode
# Scanner Android project
#
# Author: Neha Pandey
from urllib2 import urlopen
from urllib import urlencode
import sys
def translate (in_lang, out_lang, input):
"""Translate the input from in_lang to out_lang using Google Translate"""
# Create the URL
langpair = '%s|%s' % (in_lang, out_lang)
base = 'http://ajax.googleapis.com/ajax/services/language/translate?'
params = urlencode ((('v',1.0),
('q',input),
('langpair',langpair),) )
url = base + params
# Call translation
content = urlopen(url).read()
# Snip out unwanted fluff from the translation
start_index = content.find('"translatedText":"') + 18
translation = content [start_index:]
end_index = translation.find('"}, "')
output = translation[:end_index]
return output
# All the languages to translate to
language_list = ['en', 'ar', 'cs', 'da', 'de', 'es',
'fi', 'fr', 'hu', 'it', 'ja', 'nl',
'pl', 'pt', 'ru', 'sv', 'zh-CN',
'zh-TW']
if (len(sys.argv) < 3):
print "Usage: %s name String to translate" % sys.argv[0]
print "Sample: %s ask-banana Give me a banana" % sys.argv[0]
import sys
sys.exit (-1);
# First argument is the name of the string
string_name = sys.argv[1]
# Remaining arguments is the string to be translated in English
input_string =' '.join(sys.argv[2:])
# Translate all languages
for i in range(len(language_list)) :
translation = translate ('en', language_list[i], input_string)
xml_string = '<string name="' + string_name + '">' + \
translation + '</string>'
print language_list[i], xml_string