Index: src/ictranslate/ICTranslateDlg.cpp =================================================================== diff -u -r2ffaff594233ce671e00b842c718cca32f9498c5 -rd99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86 --- src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision 2ffaff594233ce671e00b842c718cca32f9498c5) +++ src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision d99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86) @@ -92,6 +92,9 @@ ON_BN_CLICKED(IDAPPLY, &CICTranslateDlg::OnBnClickedApply) ON_BN_CLICKED(IDC_CHOOSE_FONT_BUTTON, &CICTranslateDlg::OnBnClickedChooseFontButton) ON_COMMAND(ID_EDIT_CLEANUP_TRANSLATION, &CICTranslateDlg::OnEditCleanupTranslation) + ON_COMMAND(ID_FILE_NEWTRANSLATION, &CICTranslateDlg::OnFileNewTranslation) + ON_COMMAND(ID_FILE_SAVETRANSLATIONAS, &CICTranslateDlg::OnFileSavetranslationAs) + ON_COMMAND(ID_FILE_SAVETRANSLATION, &CICTranslateDlg::OnFileSaveTranslation) END_MESSAGE_MAP() @@ -213,6 +216,7 @@ } UpdateBaseLanguageList(); + UpdateCustomLanguageList(); } } @@ -524,7 +528,7 @@ ictranslate::CTranslationItem* pCustomItem = m_ldCustom.GetTranslationItem(uiID, true); if(pCustomItem) { - pCustomItem->SetText(strText); + pCustomItem->SetText(strText, false); pCustomItem->SetChecksum(pBaseItem->GetChecksum()); } @@ -584,3 +588,60 @@ m_ldCustom.CleanupTranslation(m_ldBase); UpdateCustomLanguageList(); } + +void CICTranslateDlg::OnFileNewTranslation() +{ + // clear the custom translation + m_ldCustom.Clear(); + UpdateCustomLanguageList(); +} + +void CICTranslateDlg::OnFileSavetranslationAs() +{ + CString strFilename = m_ldCustom.GetFilename(false); + CString strPath = m_ldCustom.GetFilename(true); + + CFileDialog dlg(FALSE, _T(".lng"), strFilename, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Language files (*.lng)|*.lng|All files (*.*)|*.*||"), this); + if(dlg.DoModal()) + { + // store additional informations from the dialog box + CString str; + m_ctlDstAuthor.GetWindowText(str); + m_ldCustom.SetAuthor(str); + m_ctlDstLanguageName.GetWindowText(str); + m_ldCustom.SetLangName(str); + m_ctlDstHelpFilename.GetWindowText(str); + m_ldCustom.SetHelpName(str); + bool bRTL = (m_ctlDstRTL.GetCheck() == BST_CHECKED); + m_ldCustom.SetDirection(bRTL); + + // store translation with new name + m_ldCustom.WriteTranslation(dlg.GetPathName()); + m_ctlDstFilename.SetWindowText(m_ldCustom.GetFilename(true)); + } +} + +void CICTranslateDlg::OnFileSaveTranslation() +{ + CString strPath = m_ldCustom.GetFilename(true); + if(strPath.IsEmpty()) + { + OnFileSavetranslationAs(); + } + else + { + // store additional informations from the dialog box + CString str; + m_ctlDstAuthor.GetWindowText(str); + m_ldCustom.SetAuthor(str); + m_ctlDstLanguageName.GetWindowText(str); + m_ldCustom.SetLangName(str); + m_ctlDstHelpFilename.GetWindowText(str); + m_ldCustom.SetHelpName(str); + bool bRTL = (m_ctlDstRTL.GetCheck() == BST_CHECKED); + m_ldCustom.SetDirection(bRTL); + + m_ldCustom.WriteTranslation(NULL); + m_ctlDstFilename.SetWindowText(m_ldCustom.GetFilename(true)); + } +} Index: src/ictranslate/ICTranslateDlg.h =================================================================== diff -u -r2ffaff594233ce671e00b842c718cca32f9498c5 -rd99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86 --- src/ictranslate/ICTranslateDlg.h (.../ICTranslateDlg.h) (revision 2ffaff594233ce671e00b842c718cca32f9498c5) +++ src/ictranslate/ICTranslateDlg.h (.../ICTranslateDlg.h) (revision d99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86) @@ -68,4 +68,7 @@ CButton m_ctlDstRTL; afx_msg void OnBnClickedChooseFontButton(); afx_msg void OnEditCleanupTranslation(); + afx_msg void OnFileNewTranslation(); + afx_msg void OnFileSavetranslationAs(); + afx_msg void OnFileSaveTranslation(); }; Index: src/libictranslate/ResourceManager.cpp =================================================================== diff -u -r2ffaff594233ce671e00b842c718cca32f9498c5 -rd99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86 --- src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision 2ffaff594233ce671e00b842c718cca32f9498c5) +++ src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision d99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86) @@ -97,7 +97,7 @@ m_uiChecksum = 0; } -void CTranslationItem::SetText(const tchar_t* pszText) +void CTranslationItem::SetText(const tchar_t* pszText, bool bUnescapeString) { delete [] m_pszText; if(pszText) @@ -107,7 +107,8 @@ { m_pszText = new tchar_t[m_stTextLength + 1]; _tcscpy(m_pszText, pszText); - UnescapeString(); + if(bUnescapeString) + UnescapeString(); return; } } @@ -379,7 +380,7 @@ assert(itTranslation != pLangData->m_mapTranslation.end()); if(itTranslation != pLangData->m_mapTranslation.end()) { - (*itTranslation).second.SetText(pszValue); + (*itTranslation).second.SetText(pszValue, true); if(!pLangData->m_bUpdating) (*itTranslation).second.SetChecksum(uiChecksum); } @@ -501,6 +502,58 @@ } } +void CLangData::WriteTranslation(PCTSTR pszPath) +{ + const int iBufferSize = 256; + tchar_t szTemp[iBufferSize]; + + // load data from file + icpf::config cfg(icpf::config::eIni); + cfg.set_string(_t("Info/Lang Name"), m_pszLngName); + cfg.set_string(_T("Info/Lang Code"), _itot(m_wLangCode, szTemp, 10)); + cfg.set_string(_T("Info/Base Language"), _T("")); + cfg.set_string(_T("Info/Font Face"), m_pszFontFace); + cfg.set_string(_T("Info/Charset"), _itot(m_byCharset, szTemp, 10)); + cfg.set_string(_T("Info/Size"), _itot(m_wPointSize, szTemp, 10)); + cfg.set_string(_T("Info/RTL reading order"), m_bRTL ? _T("1") : _T("0")); + cfg.set_string(_T("Info/Help name"), m_pszHelpName); + cfg.set_string(_T("Info/Author"), m_pszAuthor); + cfg.set_string(_T("Info/Version"), m_pszVersion); + + tstring_t strText; + for(translation_map::iterator it = m_mapTranslation.begin(); it != m_mapTranslation.end(); it++) + { + uint_t uiKey = (*it).first; + _sntprintf(szTemp, iBufferSize - 1, UIFMT _T("/") UIFMT _T("[") UIXFMT _T("]"), (uiKey >> 16), uiKey & 0x0000ffff, (*it).second.GetChecksum()); + + strText = (*it).second.GetText(); + tstring_t::size_type stPos; + while((stPos = strText.find_first_of(_t("\r\n\t"))) != tstring_t::npos) + { + switch(strText[stPos]) + { + case _t('\r'): + strText.replace(stPos, 1, _t("\\r")); + break; + case _t('\n'): + strText.replace(stPos, 1, _t("\\n")); + break; + case _t('\t'): + strText.replace(stPos, 1, _t("\\t")); + break; + } + } + + cfg.set_string(szTemp, strText.c_str()); + } + + if(pszPath == NULL) + pszPath = m_pszFilename; + else + SetFilename(pszPath); + cfg.write(pszPath); +} + PCTSTR CLangData::GetString(WORD wHiID, WORD wLoID) { translation_map::const_iterator it=m_mapTranslation.find((wHiID << 16) | wLoID); @@ -572,11 +625,14 @@ return m_pszFilename; else { - TCHAR *pszFnd=_tcsrchr(m_pszFilename, _T('\\')); - if (pszFnd) - return pszFnd+1; - else - return m_pszFilename; + if(m_pszFilename) + { + TCHAR *pszFnd=_tcsrchr(m_pszFilename, _T('\\')); + if (pszFnd) + return pszFnd+1; + } + + return m_pszFilename; } } Index: src/libictranslate/ResourceManager.h =================================================================== diff -u -r2ffaff594233ce671e00b842c718cca32f9498c5 -rd99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86 --- src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 2ffaff594233ce671e00b842c718cca32f9498c5) +++ src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision d99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86) @@ -54,7 +54,7 @@ void CalculateChecksum(); const tchar_t* GetText() const { return m_pszText; } - void SetText(const tchar_t* pszText); + void SetText(const tchar_t* pszText, bool bUnescapeString); uint_t GetChecksum() const { return m_uiChecksum; } void SetChecksum(uint_t uiChecksum) { m_uiChecksum = uiChecksum; } @@ -83,6 +83,7 @@ // operations bool ReadInfo(PCTSTR pszFile); bool ReadTranslation(PCTSTR pszFile, bool bReadBase = false); + void WriteTranslation(PCTSTR pszPath); // translation retrieving/setting const tchar_t* GetString(WORD wHiID, WORD wLoID); // retrieves string using group id and string id @@ -129,6 +130,7 @@ protected: void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); static void EnumAttributesCallback(bool bGroup, const tchar_t* pszName, const tchar_t* pszValue, ptr_t pData); + static void WriteAttributesCallback(bool bGroup, const tchar_t* pszName, const tchar_t* pszValue, ptr_t pData); static void UnescapeString(tchar_t* pszData); protected: