Skip to content

Commit

Permalink
add infrastructure for crowdsourcing internationalization project
Browse files Browse the repository at this point in the history
ready to build GeoDa with new Chinese language package
  • Loading branch information
lixun910 committed May 15, 2019
1 parent 111237c commit c4c5aeb
Show file tree
Hide file tree
Showing 25 changed files with 21,459 additions and 6,620 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ osm/
internationalization/.vscode/launch.json
*.swo
internationalization/pofiles/new_zh_CN.mo
internationalization/.vscode/settings.json
internationalization/~$zh_CN.xlsx
2 changes: 1 addition & 1 deletion DialogTools/HClusterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void HClusterDlg::CreateControls()
gbox->Add(chk_contiguity, 1, wxEXPAND);
chk_contiguity->Disable();

wxStaticText* st16 = new wxStaticText(panel, wxID_ANY, _(""),
wxStaticText* st16 = new wxStaticText(panel, wxID_ANY, "",
wxDefaultPosition, wxSize(128,-1));
combo_weights = new wxChoice(panel, wxID_ANY, wxDefaultPosition,
wxSize(200,-1));
Expand Down
2 changes: 1 addition & 1 deletion DialogTools/MaxpDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void MaxpDlg::CreateControls()

// Min regions
st_minregions = new wxStaticText(panel, wxID_ANY, _("Min # per Region:"), wxDefaultPosition, wxSize(128,-1));
txt_minregions = new wxTextCtrl(panel, wxID_ANY, _(""), wxDefaultPosition, wxSize(200,-1));
txt_minregions = new wxTextCtrl(panel, wxID_ANY, "", wxDefaultPosition, wxSize(200,-1));
txt_minregions->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
gbox->Add(st_minregions, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 10);
gbox->Add(txt_minregions, 1, wxEXPAND);
Expand Down
4 changes: 2 additions & 2 deletions DialogTools/RandomizationDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ InferenceSettingsDlg::InferenceSettingsDlg(wxWindow* parent,
wxFlexGridSizer* gbox = new wxFlexGridSizer(9,2,10,0);

m_rdo_1 = new wxRadioButton(panel, wxID_ANY, _("Bonferroni bound:"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
m_txt_bo = new wxStaticText(panel, wxID_ANY, _(""), wxDefaultPosition, wxSize(150,-1));
m_txt_bo = new wxStaticText(panel, wxID_ANY, "", wxDefaultPosition, wxSize(150,-1));
gbox->Add(m_rdo_1, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 10);
gbox->Add(m_txt_bo, 1, wxEXPAND);

m_rdo_2 = new wxRadioButton(panel, wxID_ANY, _("False Discovery Rate:"), wxDefaultPosition, wxDefaultSize);
m_txt_fdr = new wxStaticText(panel, wxID_ANY, _(""), wxDefaultPosition, wxSize(150,-1));
m_txt_fdr = new wxStaticText(panel, wxID_ANY, "", wxDefaultPosition, wxSize(150,-1));
gbox->Add(m_rdo_2, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 10);
gbox->Add(m_txt_fdr, 1, wxEXPAND);

Expand Down
2 changes: 1 addition & 1 deletion DialogTools/SkaterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void SkaterDlg::CreateControls()

// Min regions
st_minregions = new wxStaticText(panel, wxID_ANY, _("Min Region Size:"), wxDefaultPosition, wxSize(128,-1));
txt_minregions = new wxTextCtrl(panel, wxID_ANY, _(""), wxDefaultPosition, wxSize(200,-1));
txt_minregions = new wxTextCtrl(panel, wxID_ANY, "", wxDefaultPosition, wxSize(200,-1));
txt_minregions->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
gbox->Add(st_minregions, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 10);
gbox->Add(txt_minregions, 1, wxEXPAND);
Expand Down
2 changes: 1 addition & 1 deletion DialogTools/VariableSettingsDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void DiffMoranVarSettingDlg::CreateControls()
wxStaticText *st3 = new wxStaticText (panel, wxID_ANY, _("Weights"),
wxDefaultPosition, wxSize(70,-1));

wxComboBox* box3 = new wxComboBox(panel, wxID_ANY, _(""), wxDefaultPosition,
wxComboBox* box3 = new wxComboBox(panel, wxID_ANY, "", wxDefaultPosition,
wxSize(160,-1), 0, NULL, wxCB_READONLY);

hbox1->Add(st3, 0, wxALIGN_CENTER | wxLEFT| wxTOP | wxBOTTOM, 10);
Expand Down
26 changes: 13 additions & 13 deletions arizona/viz3/plots/scatterplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,42 +142,42 @@ void fOGLErrHandler(int err, int glerr, const GLchar* glMsg)
switch (err)
{
case myoglERR_SHADERCREATE:
msg = _("Error in shader creation.");
msg = "Error in shader creation.";
break;
case myoglERR_SHADERCOMPILE:
msg = _("Error in shader compilation.");
msg = "Error in shader compilation.";
break;
case myoglERR_SHADERLINK:
msg = _("Error in shader linkage.");
msg = "Error in shader linkage.";
break;
case myoglERR_SHADERLOCATION:
msg = _("Error: Can't get uniforms locations.");
msg = "Error: Can't get uniforms locations.";
break;
case myoglERR_BUFFER:
msg = _("Error: Can't load buffer. Likely out of GPU memory.");
msg = "Error: Can't load buffer. Likely out of GPU memory.";
break;
case myoglERR_TEXTIMAGE:
msg = _("Error: Can't load texture. Likely out of GPU memory.");
msg = "Error: Can't load texture. Likely out of GPU memory.";
break;
case myoglERR_DRAWING_TRI:
msg = _("Error: Can't draw the triangles.");
msg = "Error: Can't draw the triangles.";
break;
case myoglERR_DRAWING_STR:
msg = _("Error: Can't draw the string.");
msg = "Error: Can't draw the string.";
break;
case myoglERR_JUSTLOG:
msg = _("Log info: ");
msg = "Log info: ";
break;
default:
msg = _("Not a GL message.");
msg = "Not a GL message.";
}

if ( glerr != GL_NO_ERROR )
msg += wxString::Format(_(" GL error %d. "), glerr);
msg += wxString::Format(" GL error %d. ", glerr);
else if ( err == 0 )
msg = _("Information: ");
msg = "Information: ";
else if ( err != myoglERR_JUSTLOG )
msg += _(" GL reports: ");
msg += " GL reports: ";

if ( glMsg != NULL )
msg += wxString::FromUTF8( reinterpret_cast<const char *>(glMsg) );
Expand Down
4 changes: 4 additions & 0 deletions internationalization/1_create_geoda_pot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# create_geoda_pot.sh
# the first part will use find() command to find _() strings from
find .. \( -name '*.cpp' -o -name '*.h' \) -not -path "../BuildTools/*" | xargs xgettext -d geoda -s --keyword=_ -p ./ -o geoda.pot
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def process_xrc(xrcfile):


def create_po(txtfiles):
pofile = 'xrc.po'
pofile = 'xrc.pot'
en_strings = {}
for txtfile in txtfiles:
f = open(txtfile)
Expand Down
44 changes: 44 additions & 0 deletions internationalization/3_get_diff_PO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python

from __future__ import print_function
import re
import csv
import sys
import argparse
from po2csv import po2dict, dict2PO

def getDiffPO(po_file, all_items):
new_items = {}

# read from po_file
current_items = {}
po2dict(po_file, current_items)

# use all_items as ground to find diff (than po_file)
msgid_list = all_items.keys()
for msgid in msgid_list:
if msgid not in current_items:
new_items[msgid] = all_items[msgid]

return new_items


parser = argparse.ArgumentParser(description='Get new items by comparing existing PO file (e.g. zh_CN.po, specified using argument --input) with new POT files (geoda.pot and xrc.pot extracted from source code). New msgid with empty msgstr will be written into a new PO file specified by argument --output')
parser.add_argument('pot_files', type=str, nargs='+', help='paths of template POT files')
parser.add_argument('--input', required=True, dest='input_po_file', type=str, help='path of an existing to-be-updated po_file')
parser.add_argument('--output', required=True, dest='output_po_file', help='path of an output po_file')
args = parser.parse_args()

if __name__ == "__main__":
pot_files = args.pot_files
exist_po = args.input_po_file
output_po = args.output_po_file

# construct a dictionary from all POT file,
# so that newly added msgid will be included
all_items = {}
for pot in pot_files:
po2dict(pot, all_items)

new_items = getDiffPO(exist_po, all_items)
dict2PO(new_items, output_po)
44 changes: 44 additions & 0 deletions internationalization/3_updatePO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python

from __future__ import print_function
import re
import csv
import sys
import argparse
from po2csv import po2dict, dict2PO

def updatePO(po_file, all_items):
new_items = all_items.copy()

# read from po_file
current_items = {}
po2dict(po_file, current_items)

# use all_items as ground
msgid_list = all_items.keys()
for msgid in msgid_list:
if msgid in current_items:
new_items[msgid] = current_items[msgid]

return new_items


parser = argparse.ArgumentParser(description='Update existing PO file (e.g. zh_CN.po, specified using argument --input) using POT files (geoda.pot and xrc.pot extracted from source code. New msgid with empty msgstr will be added into existing PO file and saved into a new file specified by argument --output')
parser.add_argument('pot_files', type=str, nargs='+', help='paths of template POT files')
parser.add_argument('--input', required=True, dest='input_po_file', type=str, help='path of an existing to-be-updated po_file')
parser.add_argument('--output', required=True, dest='output_po_file', help='path of an output po_file')
args = parser.parse_args()

if __name__ == "__main__":
pot_files = args.pot_files
exist_po = args.input_po_file
output_po = args.output_po_file

# construct a dictionary from all POT file,
# so that newly added msgid will be included
all_items = {}
for pot in pot_files:
po2dict(pot, all_items)

all_items = updatePO(exist_po, all_items)
dict2PO(all_items, output_po)
20 changes: 0 additions & 20 deletions internationalization/create_newpo.py

This file was deleted.

1 change: 1 addition & 0 deletions internationalization/credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"installed":{"client_id":"911148186542-n9brf1e9bh4vq07229n3d604t8kenodr.apps.googleusercontent.com","project_id":"quickstart-1557874589303","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"tSA4X8GKgSwkkgPCck5xgzof","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
27 changes: 27 additions & 0 deletions internationalization/csv2po.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python

from __future__ import print_function
import re
import sys

def csv2po(csv_file, po_file):
with open(csv_file) as f, open(po_file, 'w') as o:
for i, line in enumerate(f, 1):
if (i == 0):
continue
line = line.strip()
if (len(line) == 0):
continue
msgid, msgstr, contrib = line.split('`')
line = 'msgid "' + msgid + '"\n'
o.write(line)
line = 'msgstr "' + msgstr + '"\n'
o.write(line)

if __name__ == "__main__":
if (len(sys.argv) != 3) :
print("Usage: python csv2po.py csv_file po_file")
else:
csv_file, po_file = sys.argv[1:]
if (po_file and csv_file):
csv2po(csv_file, po_file)
Loading

0 comments on commit c4c5aeb

Please sign in to comment.