separate course and song translations, so they don't interfere
with one another
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
# first loaded. Delete the files in the "Cache" directory after making
|
# first loaded. Delete the files in the "Cache" directory after making
|
||||||
# changes.
|
# changes.
|
||||||
|
|
||||||
|
[Songs]
|
||||||
TitleFrom: Candy
|
TitleFrom: Candy
|
||||||
ArtistFrom: Luv.*
|
ArtistFrom: Luv.*
|
||||||
TitleTo: CANDY☆
|
TitleTo: CANDY☆
|
||||||
@@ -307,7 +308,7 @@ ArtistTo: 堀江由衣
|
|||||||
ArtistFrom: (Nobuo Uematsu)|(Uematsu Nobuo)
|
ArtistFrom: (Nobuo Uematsu)|(Uematsu Nobuo)
|
||||||
ArtistTo: 植松伸夫
|
ArtistTo: 植松伸夫
|
||||||
|
|
||||||
# Courses:
|
[Courses]
|
||||||
TitleFrom: Kidou
|
TitleFrom: Kidou
|
||||||
TitleTo: 鬼道
|
TitleTo: 鬼道
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ void Course::LoadFromCRSFile( CString sPath )
|
|||||||
else
|
else
|
||||||
LOG->Trace( "Unexpected value named '%s'", sValueName.GetString() );
|
LOG->Trace( "Unexpected value named '%s'", sValueName.GetString() );
|
||||||
}
|
}
|
||||||
static TitleSubst tsub;
|
static TitleSubst tsub("courses");
|
||||||
|
|
||||||
CString ignore;
|
CString ignore;
|
||||||
tsub.Subst(m_sName, ignore, ignore,
|
tsub.Subst(m_sName, ignore, ignore,
|
||||||
|
|||||||
@@ -583,7 +583,7 @@ void Song::TidyUpData()
|
|||||||
|
|
||||||
void Song::TranslateTitles()
|
void Song::TranslateTitles()
|
||||||
{
|
{
|
||||||
static TitleSubst tsub;
|
static TitleSubst tsub("songs");
|
||||||
|
|
||||||
tsub.Subst(m_sMainTitle, m_sSubTitle, m_sArtist,
|
tsub.Subst(m_sMainTitle, m_sSubTitle, m_sArtist,
|
||||||
m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit);
|
m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit);
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ struct TitleTrans
|
|||||||
TitleTrans(CString tf, CString sf, CString af, CString tt, CString st, CString at,
|
TitleTrans(CString tf, CString sf, CString af, CString tt, CString st, CString at,
|
||||||
bool translit_):
|
bool translit_):
|
||||||
TitleFrom(tf), SubFrom(sf), ArtistFrom(af),
|
TitleFrom(tf), SubFrom(sf), ArtistFrom(af),
|
||||||
TitleTo(tt), SubTo(st), ArtistTo(at),
|
TitleTo(tt), SubTo(st), ArtistTo(at), translit(translit_) { }
|
||||||
translit(translit_) { }
|
|
||||||
|
|
||||||
bool Matches(CString title, CString sub, CString artist);
|
bool Matches(CString title, CString sub, CString artist);
|
||||||
};
|
};
|
||||||
@@ -33,7 +32,8 @@ bool TitleTrans::Matches(CString title, CString sub, CString artist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TitleSubst::AddTrans(const CString &tf, const CString &sf, const CString &af,
|
void TitleSubst::AddTrans(const CString &tf, const CString &sf, const CString &af,
|
||||||
const CString &tt, const CString &st, const CString &at, bool translit)
|
const CString &tt, const CString &st, const CString &at,
|
||||||
|
bool translit)
|
||||||
{
|
{
|
||||||
ttab.push_back(new TitleTrans(tf, sf, af, tt, st, at, translit));
|
ttab.push_back(new TitleTrans(tf, sf, af, tt, st, at, translit));
|
||||||
}
|
}
|
||||||
@@ -70,23 +70,23 @@ void TitleSubst::Subst(CString &title, CString &subtitle, CString &artist,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TitleSubst::TitleSubst()
|
TitleSubst::TitleSubst(const CString §ion)
|
||||||
{
|
{
|
||||||
Load("Translation.dat");
|
Load("Translation.dat", section);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleSubst::Load(const CString &filename)
|
void TitleSubst::Load(const CString &filename, const CString §ion)
|
||||||
{
|
{
|
||||||
ifstream f;
|
ifstream f;
|
||||||
f.open(filename);
|
f.open(filename);
|
||||||
if(!f.good()) return;
|
if(!f.good()) return;
|
||||||
while(!f.eof())
|
|
||||||
{
|
|
||||||
CString TitleFrom, ArtistFrom, SubtitleFrom, TitleTo, ArtistTo, SubtitleTo;
|
CString TitleFrom, ArtistFrom, SubtitleFrom, TitleTo, ArtistTo, SubtitleTo;
|
||||||
bool translit = true;
|
bool translit = true;
|
||||||
|
CString CurrentSection;
|
||||||
|
|
||||||
while(!f.eof())
|
while(!f.eof())
|
||||||
{
|
{
|
||||||
|
|
||||||
CString line;
|
CString line;
|
||||||
if(!getline(f, line)) continue;
|
if(!getline(f, line)) continue;
|
||||||
|
|
||||||
@@ -100,21 +100,20 @@ void TitleSubst::Load(const CString &filename)
|
|||||||
TrimLeft(line);
|
TrimLeft(line);
|
||||||
TrimRight(line);
|
TrimRight(line);
|
||||||
|
|
||||||
|
if(line.size() == 0) continue; /* blank */
|
||||||
|
if(line[0] == '#') continue; /* comment */
|
||||||
|
|
||||||
|
|
||||||
if(!line.CompareNoCase("DontTransliterate"))
|
if(!line.CompareNoCase("DontTransliterate"))
|
||||||
{
|
{
|
||||||
translit = false;
|
translit = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line.size() == 0) continue; /* blank */
|
|
||||||
if(line[0] == '#') continue; /* comment */
|
|
||||||
|
|
||||||
if(line[0] == '*') break;
|
|
||||||
|
|
||||||
/* x: y */
|
|
||||||
|
|
||||||
unsigned pos = line.find_first_of(':');
|
unsigned pos = line.find_first_of(':');
|
||||||
if(pos == string::npos) continue;
|
if(pos != string::npos)
|
||||||
|
{
|
||||||
|
/* x: y */
|
||||||
CString id = line.substr(0, pos);
|
CString id = line.substr(0, pos);
|
||||||
CString txt = line.substr(pos+1);
|
CString txt = line.substr(pos+1);
|
||||||
TrimLeft(txt);
|
TrimLeft(txt);
|
||||||
@@ -127,13 +126,29 @@ void TitleSubst::Load(const CString &filename)
|
|||||||
else if(!id.CompareNoCase("SubtitleTo")) SubtitleTo = txt;
|
else if(!id.CompareNoCase("SubtitleTo")) SubtitleTo = txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add the translation if this is a terminator (*) or section
|
||||||
|
* marker ([xxx]). */
|
||||||
|
if(line[0] == '*' || line[0] == '[')
|
||||||
|
{
|
||||||
/* Surround each regex with ^(...)$, to force all comparisons to default
|
/* Surround each regex with ^(...)$, to force all comparisons to default
|
||||||
* to being a full-line match. (Add ".*" manually if htis isn't wanted.) */
|
* to being a full-line match. (Add ".*" manually if htis isn't wanted.) */
|
||||||
if(TitleFrom.size()) TitleFrom = "^(" + TitleFrom + ")$";
|
if(TitleFrom.size()) TitleFrom = "^(" + TitleFrom + ")$";
|
||||||
if(ArtistFrom.size()) ArtistFrom = "^(" + ArtistFrom + ")$";
|
if(ArtistFrom.size()) ArtistFrom = "^(" + ArtistFrom + ")$";
|
||||||
if(SubtitleFrom.size()) SubtitleFrom = "^(" + SubtitleFrom + ")$";
|
if(SubtitleFrom.size()) SubtitleFrom = "^(" + SubtitleFrom + ")$";
|
||||||
|
|
||||||
|
if(!CurrentSection.CompareNoCase(section) &&
|
||||||
|
(TitleFrom.size() || SubtitleFrom.size() || ArtistFrom.size()))
|
||||||
AddTrans(TitleFrom, SubtitleFrom, ArtistFrom, TitleTo, SubtitleTo, ArtistTo, translit);
|
AddTrans(TitleFrom, SubtitleFrom, ArtistFrom, TitleTo, SubtitleTo, ArtistTo, translit);
|
||||||
|
|
||||||
|
/* Reset. */
|
||||||
|
TitleFrom = ArtistFrom = SubtitleFrom = TitleTo = ArtistTo = SubtitleTo = "";
|
||||||
|
translit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(line[0] == '[' && line[line.size()-1] == ']')
|
||||||
|
{
|
||||||
|
CurrentSection = line.substr(1, line.size()-2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ class TitleSubst
|
|||||||
void AddTrans(const CString &tf, const CString &sf, const CString &af,
|
void AddTrans(const CString &tf, const CString &sf, const CString &af,
|
||||||
const CString &tt, const CString &st, const CString &at, bool translit);
|
const CString &tt, const CString &st, const CString &at, bool translit);
|
||||||
public:
|
public:
|
||||||
TitleSubst();
|
TitleSubst(const CString §ion);
|
||||||
~TitleSubst();
|
~TitleSubst();
|
||||||
|
|
||||||
void Load(const CString &filename);
|
void Load(const CString &filename, const CString §ion);
|
||||||
|
|
||||||
void Subst(CString &title, CString &sub, CString &artist,
|
void Subst(CString &title, CString &sub, CString &artist,
|
||||||
CString &ttitle, CString &tsub, CString &tartist);
|
CString &ttitle, CString &tsub, CString &tartist);
|
||||||
|
|||||||
Reference in New Issue
Block a user