Skip to content

Commit

Permalink
Bumped version 1.0.0.13.
Browse files Browse the repository at this point in the history
Added fuzzy ID matching.
  • Loading branch information
raspopov committed Apr 2, 2017
1 parent 02c9c6a commit e27290e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
Binary file modified Polang.rc
Binary file not shown.
14 changes: 12 additions & 2 deletions PolangDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VAL_POT _T("PotPath")
#define VAL_WINDOW _T("Window")
#define VAL_PRESERVE _T("Preserve")
#define VAL_FUZZY _T("Fuzzy")

// CPolangDlg dialog

Expand All @@ -46,6 +47,7 @@ CPolangDlg::CPolangDlg(CWnd* pParent /*=NULL*/)
, m_nOptions ( theApp.GetProfileInt( SETTINGS, VAL_OPTIONS, OPT_POT ) )
, m_nOptionsLast ( OPT_NULL )
, m_bPreserve ( theApp.GetProfileInt( SETTINGS, VAL_PRESERVE, TRUE ) )
, m_bFuzzy ( theApp.GetProfileInt( SETTINGS, VAL_FUZZY, TRUE ) )
{
}

Expand All @@ -69,8 +71,12 @@ void CPolangDlg::DoDataExchange(CDataExchange* pDX)
DDX_Control( pDX, IDC_2_3_SET, m_wnd23Set );

DDX_Radio( pDX, IDC_RADIO1, m_nOptions );

DDX_Check( pDX, IDC_FORMAT, m_bPreserve );
DDX_Control( pDX, IDC_FORMAT, m_wndPreserve );

DDX_Check( pDX, IDC_FUZZY, m_bFuzzy );
DDX_Control( pDX, IDC_FUZZY, m_wndFuzzy );
}

void CPolangDlg::UpdateInterface(int nOptions)
Expand Down Expand Up @@ -127,6 +133,7 @@ void CPolangDlg::UpdateInterface(int nOptions)
m_wnd2File.SetWindowText( s2Filename );
m_wnd2File.SetCueBanner( _T("en_US.pot") );
m_wnd12Set.EnableWindow();
m_wndFuzzy.EnableWindow( FALSE );
// Disabled
m_wnd3Title.SetWindowText( _T("") );
m_wnd3File.EnableWindow( FALSE );
Expand Down Expand Up @@ -158,6 +165,7 @@ void CPolangDlg::UpdateInterface(int nOptions)
m_wnd2File.SetWindowText( s2Filename );
m_wnd2File.SetCueBanner( _T("ru_RU.lang") );
m_wnd12Set.EnableWindow( FALSE );
m_wndFuzzy.EnableWindow();
// Output
m_wnd3Title.SetWindowText( LoadString( IDS_PO_TITLE ) );
m_wnd3File.EnableWindow();
Expand Down Expand Up @@ -192,6 +200,7 @@ void CPolangDlg::UpdateInterface(int nOptions)
m_wnd2File.SetWindowText( s2Filename );
m_wnd2File.SetCueBanner( _T("ru_RU.po") );
m_wnd12Set.EnableWindow( FALSE );
m_wndFuzzy.EnableWindow( FALSE );
// Output
m_wnd3Title.SetWindowText( LoadString( IDS_LANG_TITLE ) );
m_wnd3File.EnableWindow();
Expand Down Expand Up @@ -219,6 +228,7 @@ void CPolangDlg::UpdateInterface(int nOptions)
}

theApp.WriteProfileInt( SETTINGS, VAL_PRESERVE, m_bPreserve );
theApp.WriteProfileInt( SETTINGS, VAL_FUZZY, m_bFuzzy );
}

BEGIN_MESSAGE_MAP(CPolangDlg, CDialogEx)
Expand Down Expand Up @@ -376,7 +386,7 @@ void CPolangDlg::OnOK()

if ( ! s2Filename.IsEmpty() )
{
if ( ! translations.LoadLang( s2Filename, true ) )
if ( ! translations.LoadLang( s2Filename, true, m_bFuzzy ) )
{
AfxMessageBox( IDS_MSG_LANG_ERROR, MB_OK | MB_ICONEXCLAMATION );
return;
Expand Down Expand Up @@ -412,7 +422,7 @@ void CPolangDlg::OnOK()
if ( m_bPreserve )
{
// Save preserving order
if ( ! translations.LoadLang( s1Filename, false, s3Filename ) )
if ( ! translations.LoadLang( s1Filename, false, false, s3Filename ) )
{
AfxMessageBox( IDS_MSG_LANG_SAVE_ERROR, MB_OK | MB_ICONEXCLAMATION );
return;
Expand Down
2 changes: 2 additions & 0 deletions PolangDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class CPolangDlg : public CDialogEx
CToolTipCtrl m_pTips;
BOOL m_bPreserve;
CButton m_wndPreserve;
BOOL m_bFuzzy;
CButton m_wndFuzzy;

void UpdateInterface(int nOptions);

Expand Down
41 changes: 27 additions & 14 deletions Translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,44 @@ void CTranslation::SetAt(const CString& sId, const CString& sMsgid)
// Add new MsgId
m_MsgidToTrans.SetAt( sMsgid, CTrans( sId ) );
}

m_IdToMsgid.SetAt( sId, sMsgid );
m_IdToMsgidFuzzy.SetAt( Fuzzy( sId ), sMsgid );
}

void CTranslation::Add(const CString& sId, const CString& sMsgstr)
void CTranslation::Add(const CString& sId, const CString& sMsgstr, bool bFuzzy)
{
CString sMsgid;
if ( m_IdToMsgid.Lookup( sId, sMsgid ) )
if ( ! m_IdToMsgid.Lookup( sId, sMsgid ) )
{
CTrans trans;
if ( m_MsgidToTrans.Lookup( sMsgid, trans ) )
{
trans.m_sMsgstr = sMsgstr;
m_MsgidToTrans.SetAt( sMsgid, trans );
}
if ( ! bFuzzy || ! m_IdToMsgidFuzzy.Lookup( Fuzzy( sId ), sMsgid ) )
return;
}

CTrans trans;
if ( m_MsgidToTrans.Lookup( sMsgid, trans ) )
{
trans.m_sMsgstr = sMsgstr;
m_MsgidToTrans.SetAt( sMsgid, trans );
}
}

void CTranslation::Add(const CStringList& lIds, const CString& sMsgstr)
void CTranslation::Add(const CStringList& lIds, const CString& sMsgstr, bool bFuzzy)
{
for ( POSITION pos = lIds.GetHeadPosition(); pos; )
{
Add( lIds.GetNext( pos ), sMsgstr );
Add( lIds.GetNext( pos ), sMsgstr, bFuzzy );
}
}

CString CTranslation::Fuzzy(__in CString str)
{
str.MakeLower(); // case-insensitive
str.Replace( _T("block"), _T("") ); // without "block" world
str.Remove( _T( '_' ) ); // without underscores
return str;
}

CStringA CTranslation::UTF8Encode(__in_bcount(nInput) LPCWSTR psInput, __in int nInput)
{
CStringA strUTF8;
Expand Down Expand Up @@ -194,7 +207,7 @@ bool CTranslation::LoadPoFromString(const CString& sContent)
case mode_msgstr:
// Save previous string
if ( ! lRef.IsEmpty() && ! sString.IsEmpty() )
Add( lRef, Decode( sString ) );
Add( lRef, Decode( sString ), false );
sString.Empty();
lRef.RemoveAll();
mode = mode_ref;
Expand Down Expand Up @@ -293,7 +306,7 @@ bool CTranslation::LoadPoFromString(const CString& sContent)
{
// Save last string
if ( ! lRef.IsEmpty() && ! sString.IsEmpty() )
Add( lRef, Decode( sString ) );
Add( lRef, Decode( sString ), false );
}

return bRet;
Expand Down Expand Up @@ -340,7 +353,7 @@ CString CTranslation::Get(const CString& sId) const
return CString();
}

bool CTranslation::LoadLang(const CString& sFilename, bool bMsgstr, const CString& sAndSaveToFilename)
bool CTranslation::LoadLang(const CString& sFilename, bool bMsgstr, bool bFuzzy, const CString& sAndSaveToFilename)
{
bool bResult = false;

Expand Down Expand Up @@ -404,7 +417,7 @@ bool CTranslation::LoadLang(const CString& sFilename, bool bMsgstr, const CStrin
else
{
if ( bMsgstr )
Add( sId, sMsgid );
Add( sId, sMsgid, bFuzzy );
else
SetAt( sId, sMsgid );
}
Expand Down
12 changes: 7 additions & 5 deletions Translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,22 @@ class CTranslation
void SetAt(const CStringList& lIds, const CString& sMsgid);

// Add localization
void Add(const CString& sId, const CString& sMsgstr);
void Add(const CStringList& lIds, const CString& sMsgstr);
void Add(const CString& sId, const CString& sMsgstr, bool bFuzzy);
void Add(const CStringList& lIds, const CString& sMsgstr, bool bFuzzy);

bool LoadPo(const CString& sFilename);
bool LoadLang(const CString& sFilename, bool bMsgstr = false, const CString& sAndSaveToFilename = CString());
bool LoadLang(const CString& sFilename, bool bMsgstr = false, bool bFuzzy = false, const CString& sAndSaveToFilename = CString());
bool SavePo(const CString& sFilename) const;
bool SaveLang(const CString& sFilename) const;

private:
CRBMap < CString, CTrans > m_MsgidToTrans;
CRBMap < CString, CString > m_IdToMsgid;
CRBMap < CString, CTrans > m_MsgidToTrans; // msgid -> msgstr
CRBMap < CString, CString > m_IdToMsgid; // land_id -> msgid
CRBMap < CString, CString > m_IdToMsgidFuzzy; // Fuzzy( land_id ) -> msgid

bool LoadPoFromString(const CString& sContent);

static CString Fuzzy(__in CString str);
static CStringA UTF8Encode(__in_bcount(nInput) LPCWSTR psInput, __in int nInput);
static CStringA UTF8Encode(__in const CStringW& strInput);
static CString Decode(__in CString str);
Expand Down
Binary file modified resource.h
Binary file not shown.

0 comments on commit e27290e

Please sign in to comment.