Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
392a09a3
Commit
392a09a3
authored
Jan 01, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nicer options for defaults in localization tr() functions
parent
de2a4414
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
56 additions
and
74 deletions
+56
-74
src/data/locale.cpp
src/data/locale.cpp
+31
-48
src/data/locale.hpp
src/data/locale.hpp
+3
-4
src/data/symbol_font.cpp
src/data/symbol_font.cpp
+4
-4
src/gui/control/card_list.cpp
src/gui/control/card_list.cpp
+1
-1
src/gui/control/card_list_column_select.cpp
src/gui/control/card_list_column_select.cpp
+2
-2
src/gui/control/native_look_editor.cpp
src/gui/control/native_look_editor.cpp
+2
-2
src/render/value/choice.cpp
src/render/value/choice.cpp
+1
-1
src/render/value/multiple_choice.cpp
src/render/value/multiple_choice.cpp
+1
-1
src/util/locale.hpp
src/util/locale.hpp
+11
-11
No files found.
src/data/locale.cpp
View file @
392a09a3
...
@@ -53,18 +53,23 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
...
@@ -53,18 +53,23 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
// ----------------------------------------------------------------------------- : Translation
// ----------------------------------------------------------------------------- : Translation
String
SubLocale
::
tr
(
const
String
&
key
)
{
String
warn_and_identity
(
const
String
&
key
)
{
handle_warning
(
_
(
"Missing key in locale: "
)
+
key
,
false
);
return
key
;
}
String
SubLocale
::
tr
(
const
String
&
key
,
DefaultLocaleFun
def
)
{
map
<
String
,
String
>::
const_iterator
it
=
translations
.
find
(
key
);
map
<
String
,
String
>::
const_iterator
it
=
translations
.
find
(
key
);
if
(
it
==
translations
.
end
())
{
if
(
it
==
translations
.
end
())
{
return
_
(
"missing:"
)
+
key
;
return
def
(
key
)
;
}
else
{
}
else
{
return
it
->
second
;
return
it
->
second
;
}
}
}
}
String
SubLocale
::
tr
(
const
String
&
key
,
const
String
&
def
)
{
String
SubLocale
::
tr
(
const
String
&
subcat
,
const
String
&
key
,
DefaultLocaleFun
def
)
{
map
<
String
,
String
>::
const_iterator
it
=
translations
.
find
(
key
);
map
<
String
,
String
>::
const_iterator
it
=
translations
.
find
(
subcat
+
_
(
" "
)
+
key
);
if
(
it
==
translations
.
end
())
{
if
(
it
==
translations
.
end
())
{
return
def
;
return
def
(
key
)
;
}
else
{
}
else
{
return
it
->
second
;
return
it
->
second
;
}
}
...
@@ -72,50 +77,28 @@ String SubLocale::tr(const String& key, const String& def) {
...
@@ -72,50 +77,28 @@ String SubLocale::tr(const String& key, const String& def) {
// from util/locale.hpp
// from util/locale.hpp
String
tr
(
LocaleCategory
cat
,
const
String
&
key
)
{
String
tr
(
LocaleCategory
cat
,
const
String
&
key
,
DefaultLocaleFun
def
)
{
if
(
!
the_locale
)
return
key
;
// no locale loaded (yet)
if
(
!
the_locale
)
return
def
(
key
);
// no locale loaded (yet)
return
the_locale
->
translations
[
cat
].
tr
(
key
);
return
the_locale
->
translations
[
cat
].
tr
(
key
,
def
);
}
}
#define IMPLEMENT_TR_TYPE(Type, type_translations) \
String
tr
(
const
Game
&
g
,
const
String
&
key
)
{
String
tr
(
const
Type
&
t
,
const
String
&
key
,
DefaultLocaleFun
def
)
{
\
if
(
!
the_locale
)
return
key
;
// no locale loaded (yet)
if
(
!
the_locale
)
return
def
(
key
);
\
SubLocaleP
loc
=
the_locale
->
game_translations
[
g
.
name
()];
SubLocaleP
loc
=
the_locale
->
type_translations
[
t
.
name
()];
\
if
(
!
loc
)
return
key
;
// no information on this game
if
(
!
loc
)
return
def
(
key
);
\
return
loc
->
tr
(
key
);
return
loc
->
tr
(
key
,
def
);
\
}
}
\
String
tr
(
const
StyleSheet
&
s
,
const
String
&
key
)
{
String
tr
(
const
Type
&
t
,
const
String
&
subcat
,
const
String
&
key
,
DefaultLocaleFun
def
)
{
\
if
(
!
the_locale
)
return
key
;
// no locale loaded (yet)
if
(
!
the_locale
)
return
def
(
key
);
\
SubLocaleP
loc
=
the_locale
->
stylesheet_translations
[
s
.
name
()];
SubLocaleP
loc
=
the_locale
->
type_translations
[
t
.
name
()];
\
if
(
!
loc
)
return
key
;
// no information on this stylesheet
if
(
!
loc
)
return
def
(
key
);
\
return
loc
->
tr
(
key
);
return
loc
->
tr
(
subcat
,
key
,
def
);
\
}
}
String
tr
(
const
SymbolFont
&
f
,
const
String
&
key
)
{
if
(
!
the_locale
)
return
key
;
// no locale loaded (yet)
SubLocaleP
loc
=
the_locale
->
symbol_font_translations
[
f
.
name
()];
if
(
!
loc
)
return
key
;
// no information on this symbol font
return
loc
->
tr
(
key
);
}
String
tr
(
const
Game
&
g
,
const
String
&
key
,
const
String
&
def
)
{
IMPLEMENT_TR_TYPE
(
Game
,
game_translations
)
if
(
!
the_locale
)
return
def
;
// no locale loaded (yet)
IMPLEMENT_TR_TYPE
(
StyleSheet
,
stylesheet_translations
)
SubLocaleP
loc
=
the_locale
->
game_translations
[
g
.
name
()];
IMPLEMENT_TR_TYPE
(
SymbolFont
,
symbol_font_translations
)
if
(
!
loc
)
return
def
;
// no information on this game
return
loc
->
tr
(
key
,
def
);
}
String
tr
(
const
StyleSheet
&
s
,
const
String
&
key
,
const
String
&
def
)
{
if
(
!
the_locale
)
return
def
;
// no locale loaded (yet)
SubLocaleP
loc
=
the_locale
->
stylesheet_translations
[
s
.
name
()];
if
(
!
loc
)
return
def
;
// no information on this stylesheet
return
loc
->
tr
(
key
,
def
);
}
String
tr
(
const
SymbolFont
&
f
,
const
String
&
key
,
const
String
&
def
)
{
if
(
!
the_locale
)
return
def
;
// no locale loaded (yet)
SubLocaleP
loc
=
the_locale
->
symbol_font_translations
[
f
.
name
()];
if
(
!
loc
)
return
def
;
// no information on this symbol font
return
loc
->
tr
(
key
,
def
);
}
// ----------------------------------------------------------------------------- : Validation
// ----------------------------------------------------------------------------- : Validation
...
...
src/data/locale.hpp
View file @
392a09a3
...
@@ -25,10 +25,9 @@ class SubLocale : public IntrusivePtrBase<SubLocale> {
...
@@ -25,10 +25,9 @@ class SubLocale : public IntrusivePtrBase<SubLocale> {
public:
public:
map
<
String
,
String
>
translations
;
map
<
String
,
String
>
translations
;
/// Translate a key
/// Translate a key, if not found, apply the default function to the key
String
tr
(
const
String
&
key
);
String
tr
(
const
String
&
key
,
DefaultLocaleFun
def
);
/// Translate a key with a default value
String
tr
(
const
String
&
subcat
,
const
String
&
key
,
DefaultLocaleFun
def
);
String
tr
(
const
String
&
key
,
const
String
&
def
);
/// Is this a valid sublocale? Returns errors
/// Is this a valid sublocale? Returns errors
String
validate
(
const
String
&
name
,
const
SubLocaleValidatorP
&
)
const
;
String
validate
(
const
String
&
name
,
const
SubLocaleValidatorP
&
)
const
;
...
...
src/data/symbol_font.cpp
View file @
392a09a3
...
@@ -481,8 +481,8 @@ String InsertSymbolMenu::getCode(int id, const SymbolFont& font) const {
...
@@ -481,8 +481,8 @@ String InsertSymbolMenu::getCode(int id, const SymbolFont& font) const {
}
else
if
(
id
==
0
&&
type
==
ITEM_CODE
)
{
}
else
if
(
id
==
0
&&
type
==
ITEM_CODE
)
{
return
name
;
return
name
;
}
else
if
(
id
==
0
&&
type
==
ITEM_CUSTOM
)
{
}
else
if
(
id
==
0
&&
type
==
ITEM_CUSTOM
)
{
String
caption
=
tr
(
font
,
_
(
"title
"
)
+
name
,
capitalize_sentence
(
name
)
);
String
caption
=
tr
(
font
,
_
(
"title
"
),
name
,
capitalize_sentence
);
String
message
=
tr
(
font
,
_
(
"message
"
)
+
name
,
capitalize_sentence
(
name
)
);
String
message
=
tr
(
font
,
_
(
"message
"
),
name
,
capitalize_sentence
);
return
wxGetTextFromUser
(
message
,
caption
);
return
wxGetTextFromUser
(
message
,
caption
);
}
}
return
wxEmptyString
;
return
wxEmptyString
;
...
@@ -501,7 +501,7 @@ wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
...
@@ -501,7 +501,7 @@ wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
}
}
wxMenuItem
*
InsertSymbolMenu
::
makeMenuItem
(
wxMenu
*
parent
,
int
first_id
,
SymbolFont
&
font
)
const
{
wxMenuItem
*
InsertSymbolMenu
::
makeMenuItem
(
wxMenu
*
parent
,
int
first_id
,
SymbolFont
&
font
)
const
{
if
(
type
==
ITEM_SUBMENU
)
{
if
(
type
==
ITEM_SUBMENU
)
{
wxMenuItem
*
item
=
new
wxMenuItem
(
parent
,
wxID_ANY
,
tr
(
font
,
_
(
"menu item
"
)
+
name
,
nam
e
),
wxMenuItem
*
item
=
new
wxMenuItem
(
parent
,
wxID_ANY
,
tr
(
font
,
_
(
"menu item
"
),
name
,
capitaliz
e
),
wxEmptyString
,
wxITEM_NORMAL
,
wxEmptyString
,
wxITEM_NORMAL
,
makeMenu
(
first_id
,
font
));
makeMenu
(
first_id
,
font
));
item
->
SetBitmap
(
wxNullBitmap
);
item
->
SetBitmap
(
wxNullBitmap
);
...
@@ -510,7 +510,7 @@ wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolF
...
@@ -510,7 +510,7 @@ wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolF
wxMenuItem
*
item
=
new
wxMenuItem
(
parent
,
wxID_SEPARATOR
);
wxMenuItem
*
item
=
new
wxMenuItem
(
parent
,
wxID_SEPARATOR
);
return
item
;
return
item
;
}
else
{
}
else
{
wxMenuItem
*
item
=
new
wxMenuItem
(
parent
,
first_id
,
tr
(
font
,
_
(
"menu item
"
)
+
name
,
nam
e
));
wxMenuItem
*
item
=
new
wxMenuItem
(
parent
,
first_id
,
tr
(
font
,
_
(
"menu item
"
),
name
,
capitaliz
e
));
// Generate bitmap for use on this item
// Generate bitmap for use on this item
SymbolInFont
*
symbol
=
nullptr
;
SymbolInFont
*
symbol
=
nullptr
;
if
(
type
==
ITEM_CUSTOM
)
{
if
(
type
==
ITEM_CUSTOM
)
{
...
...
src/gui/control/card_list.cpp
View file @
392a09a3
...
@@ -204,7 +204,7 @@ void CardListBase::rebuild() {
...
@@ -204,7 +204,7 @@ void CardListBase::rebuild() {
else
if
(
f
.
second
->
card_list_align
&
ALIGN_CENTER
)
align
=
wxLIST_FORMAT_CENTRE
;
else
if
(
f
.
second
->
card_list_align
&
ALIGN_CENTER
)
align
=
wxLIST_FORMAT_CENTRE
;
else
align
=
wxLIST_FORMAT_LEFT
;
else
align
=
wxLIST_FORMAT_LEFT
;
InsertColumn
((
long
)
column_fields
.
size
(),
InsertColumn
((
long
)
column_fields
.
size
(),
tr
(
*
set
->
game
,
f
.
second
->
card_list_name
,
capitalize
(
f
.
second
->
card_list_name
)
),
tr
(
*
set
->
game
,
f
.
second
->
card_list_name
,
capitalize
),
align
,
cs
.
width
);
align
,
cs
.
width
);
column_fields
.
push_back
(
f
.
second
);
column_fields
.
push_back
(
f
.
second
);
}
}
...
...
src/gui/control/card_list_column_select.cpp
View file @
392a09a3
...
@@ -76,7 +76,7 @@ void CardListColumnSelectDialog::initList() {
...
@@ -76,7 +76,7 @@ void CardListColumnSelectDialog::initList() {
// Init items
// Init items
Color
window_color
=
wxSystemSettings
::
GetColour
(
wxSYS_COLOUR_WINDOW
);
Color
window_color
=
wxSystemSettings
::
GetColour
(
wxSYS_COLOUR_WINDOW
);
FOR_EACH
(
c
,
columns
)
{
FOR_EACH
(
c
,
columns
)
{
list
->
Append
(
tr
(
*
game
,
c
.
field
->
card_list_name
,
capitalize
(
c
.
field
->
card_list_name
)
));
list
->
Append
(
tr
(
*
game
,
c
.
field
->
card_list_name
,
capitalize
));
// check
// check
int
i
=
list
->
GetCount
()
-
1
;
int
i
=
list
->
GetCount
()
-
1
;
list
->
Check
(
i
,
c
.
settings
.
visible
);
list
->
Check
(
i
,
c
.
settings
.
visible
);
...
@@ -89,7 +89,7 @@ void CardListColumnSelectDialog::initList() {
...
@@ -89,7 +89,7 @@ void CardListColumnSelectDialog::initList() {
void
CardListColumnSelectDialog
::
refreshItem
(
int
i
)
{
void
CardListColumnSelectDialog
::
refreshItem
(
int
i
)
{
list
->
Check
(
i
,
columns
[
i
].
settings
.
visible
);
list
->
Check
(
i
,
columns
[
i
].
settings
.
visible
);
list
->
SetString
(
i
,
tr
(
*
game
,
columns
[
i
].
field
->
card_list_name
,
capitalize
(
columns
[
i
].
field
->
card_list_name
)
)
);
list
->
SetString
(
i
,
tr
(
*
game
,
columns
[
i
].
field
->
card_list_name
,
capitalize
)
);
}
}
// ----------------------------------------------------------------------------- : Events
// ----------------------------------------------------------------------------- : Events
...
...
src/gui/control/native_look_editor.cpp
View file @
392a09a3
...
@@ -44,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
...
@@ -44,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
// draw label
// draw label
dc
.
SetFont
(
*
wxNORMAL_FONT
);
dc
.
SetFont
(
*
wxNORMAL_FONT
);
// TODO : tr using stylesheet or using game?
// TODO : tr using stylesheet or using game?
dc
.
DrawText
(
tr
(
*
set
->
game
,
s
.
fieldP
->
name
,
capitalize_sentence
(
s
.
fieldP
->
name
)
),
dc
.
DrawText
(
tr
(
*
set
->
game
,
s
.
fieldP
->
name
,
capitalize_sentence
),
RealPoint
(
margin_left
-
s
.
left
,
1
));
RealPoint
(
margin_left
-
s
.
left
,
1
));
// draw 3D border
// draw 3D border
draw_control_border
(
this
,
dc
.
getDC
(),
dc
.
trRectStraight
(
s
.
getInternalRect
().
grow
(
1
)));
draw_control_border
(
this
,
dc
.
getDC
(),
dc
.
trRectStraight
(
s
.
getInternalRect
().
grow
(
1
)));
...
@@ -70,7 +70,7 @@ void NativeLookEditor::resizeViewers() {
...
@@ -70,7 +70,7 @@ void NativeLookEditor::resizeViewers() {
// width of the label string
// width of the label string
int
w
;
int
w
;
Style
&
s
=
*
v
->
getStyle
();
Style
&
s
=
*
v
->
getStyle
();
String
text
=
tr
(
*
set
->
game
,
s
.
fieldP
->
name
,
capitalize_sentence
(
s
.
fieldP
->
name
)
);
String
text
=
tr
(
*
set
->
game
,
s
.
fieldP
->
name
,
capitalize_sentence
);
dc
.
GetTextExtent
(
text
,
&
w
,
nullptr
);
dc
.
GetTextExtent
(
text
,
&
w
,
nullptr
);
label_width
=
max
(
label_width
,
w
+
label_margin
);
label_width
=
max
(
label_width
,
w
+
label_margin
);
}
}
...
...
src/render/value/choice.cpp
View file @
392a09a3
...
@@ -85,7 +85,7 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
...
@@ -85,7 +85,7 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
}
}
}
}
if
(
style
.
render_style
&
RENDER_TEXT
)
{
if
(
style
.
render_style
&
RENDER_TEXT
)
{
String
text
=
tr
(
*
viewer
.
stylesheet
,
value
,
capitalize
(
value
)
);
String
text
=
tr
(
*
viewer
.
stylesheet
,
value
,
capitalize
_sentence
);
dc
.
SetFont
(
style
.
font
,
1.0
);
dc
.
SetFont
(
style
.
font
,
1.0
);
RealPoint
pos
=
align_in_rect
(
ALIGN_MIDDLE_LEFT
,
RealSize
(
0
,
dc
.
GetCharHeight
()),
dc
.
getInternalRect
())
+
RealSize
(
margin
,
0
);
RealPoint
pos
=
align_in_rect
(
ALIGN_MIDDLE_LEFT
,
RealSize
(
0
,
dc
.
GetCharHeight
()),
dc
.
getInternalRect
())
+
RealSize
(
margin
,
0
);
dc
.
DrawTextWithShadow
(
text
,
style
.
font
,
pos
);
dc
.
DrawTextWithShadow
(
text
,
style
.
font
,
pos
);
...
...
src/render/value/multiple_choice.cpp
View file @
392a09a3
...
@@ -74,7 +74,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
...
@@ -74,7 +74,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
}
}
if
(
style
().
render_style
&
RENDER_TEXT
)
{
if
(
style
().
render_style
&
RENDER_TEXT
)
{
// draw text
// draw text
String
text
=
tr
(
*
viewer
.
stylesheet
,
choice
,
capitalize_sentence
(
choice
)
);
String
text
=
tr
(
*
viewer
.
stylesheet
,
choice
,
capitalize_sentence
);
RealSize
text_size
=
dc
.
GetTextExtent
(
text
);
RealSize
text_size
=
dc
.
GetTextExtent
(
text
);
dc
.
DrawText
(
text
,
align_in_rect
(
ALIGN_MIDDLE_LEFT
,
text_size
,
dc
.
DrawText
(
text
,
align_in_rect
(
ALIGN_MIDDLE_LEFT
,
text_size
,
RealRect
(
pos
+
RealSize
(
size
.
width
+
1
,
0
),
RealSize
(
0
,
size
.
height
))));
RealRect
(
pos
+
RealSize
(
size
.
width
+
1
,
0
),
RealSize
(
0
,
size
.
height
))));
...
...
src/util/locale.hpp
View file @
392a09a3
...
@@ -39,26 +39,26 @@ enum LocaleCategory
...
@@ -39,26 +39,26 @@ enum LocaleCategory
,
LOCALE_CAT_MAX
,
LOCALE_CAT_MAX
};
};
typedef
String
(
*
DefaultLocaleFun
)(
const
String
&
);
/// Return the input and issue a warning
String
warn_and_identity
(
const
String
&
);
/// Translate 'key' in the category 'cat' using the current locale
/// Translate 'key' in the category 'cat' using the current locale
String
tr
(
LocaleCategory
cat
,
const
String
&
key
);
String
tr
(
LocaleCategory
cat
,
const
String
&
key
,
DefaultLocaleFun
def
=
warn_and_identity
);
/// Translate 'key' in the for a Game using the current locale
/// Translate 'key' in the for a Game using the current locale
String
tr
(
const
Game
&
,
const
String
&
key
);
String
tr
(
const
Game
&
,
const
String
&
key
,
DefaultLocaleFun
def
);
/// Translate 'key' in the for a StyleSheet using the current locale
/// Translate 'key' in the for a StyleSheet using the current locale
String
tr
(
const
StyleSheet
&
,
const
String
&
key
);
String
tr
(
const
StyleSheet
&
,
const
String
&
key
,
DefaultLocaleFun
def
);
/// Translate 'key' in the for a SymbolFont using the current locale
/// Translate 'key' in the for a SymbolFont using the current locale
String
tr
(
const
SymbolFont
&
,
const
String
&
key
);
String
tr
(
const
SymbolFont
&
,
const
String
&
key
,
DefaultLocaleFun
def
);
/// Translate 'key' in the for a Game using the current locale
/// Translate 'key' in the for a Game using the current locale
/** If the key is not found, use the default value */
String
tr
(
const
Game
&
,
const
String
&
subcat
,
const
String
&
key
,
DefaultLocaleFun
def
);
String
tr
(
const
Game
&
,
const
String
&
key
,
const
String
&
def
);
/// Translate 'key' in the for a StyleSheet using the current locale
/// Translate 'key' in the for a StyleSheet using the current locale
/** If the key is not found, use the default value */
String
tr
(
const
StyleSheet
&
,
const
String
&
subcat
,
const
String
&
key
,
DefaultLocaleFun
def
);
String
tr
(
const
StyleSheet
&
,
const
String
&
key
,
const
String
&
def
);
/// Translate 'key' in the for a SymbolFont using the current locale
/// Translate 'key' in the for a SymbolFont using the current locale
/** If the key is not found, use the default value */
String
tr
(
const
SymbolFont
&
,
const
String
&
subcat
,
const
String
&
key
,
DefaultLocaleFun
def
);
String
tr
(
const
SymbolFont
&
,
const
String
&
key
,
const
String
&
def
);
/// A localized string for menus
/// A localized string for menus
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment