Skip to content

Commit 196824f

Browse files
authored
Merge pull request #5194 from myk002/myk_translatename
Rename translation module functions and create new lua module
2 parents a575946 + 9d011da commit 196824f

34 files changed

+154
-239
lines changed

docs/changelog.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ Template for new versions:
7676
## API
7777
- ``Units::isUnitInBox``, ``Units::getUnitsInBox``: add versions accepting pos arguments
7878
- ``Units::getVisibleName``: when acting on a unit without an impersonated identity, returns the unit's name structure instead of the associated histfig's name structure
79-
- ``Translation::GenerateName``: generates in-game names, mirroring DF's internal logic
79+
- ``Translation::generateName``: generates in-game names, mirroring DF's internal logic
8080

8181
## Lua
8282
- ``dfhack.units.isUnitInBox``, ``dfhack.units.getUnitsInBox``: add versions accepting pos arguments
8383
- ``widgets.FilteredList``: search keys for list items can now be functions that return a string
84-
- ``dfhack.GenerateName``: Lua API for ``Translation::GenerateName``
84+
- ``dfhack.translation.generateName``: Lua API for ``Translation::generateName``
8585

8686
## Removed
87+
- ``dfhack.TranslateName`` has been renamed to ``dfhack.translation.translateName``
88+
- ``Translation::TranslateName`` has been renamed to ``Translation::translateName``
8789

8890
## Internals
8991
- Plugin command callbacks are now called with the core suspended by default so DF memory is always safe to access without extra steps

docs/dev/Lua API.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -949,14 +949,6 @@ can be omitted.
949949

950950
Checks if a site (e.g., a player fort) is loaded.
951951

952-
* ``dfhack.TranslateName(name[,in_english[,only_last_name]])``
953-
954-
Convert a ``df.language_name`` (or only the last name part) to string.
955-
956-
* ``dfhack.GenerateName(name,language,type,major_selector,minor_selector)``
957-
958-
Dynamically generate a name using the same logic the game itself uses.
959-
960952
* ``dfhack.df2utf(string)``
961953

962954
Convert a string from DF's CP437 encoding to UTF-8.
@@ -969,8 +961,8 @@ can be omitted.
969961
.. warning::
970962

971963
When printing CP437-encoded text to the console (for example, names returned
972-
from ``dfhack.TranslateName()``), use ``print(dfhack.df2console(text))`` to
973-
ensure proper display on all platforms.
964+
from ``dfhack.units.getReadableName()``), use
965+
``print(dfhack.df2console(text))`` to ensure proper display on all platforms.
974966

975967
* ``dfhack.utf2df(string)``
976968

@@ -1038,6 +1030,17 @@ can be omitted.
10381030
returns an ``output, command_result`` pair. ``output`` is a single string -
10391031
see ``dfhack.internal.runCommand()`` to obtain colors as well.
10401032

1033+
Translation module
1034+
------------------
1035+
1036+
* ``dfhack.translation.translateName(name[,in_english[,only_last_name]])``
1037+
1038+
Convert a ``df.language_name`` (or only the last name part) to string.
1039+
1040+
* ``dfhack.translation.generateName(name,language,type,major_selector,minor_selector)``
1041+
1042+
Dynamically generate a name using the same logic the game itself uses.
1043+
10411044
Gui module
10421045
----------
10431046

library/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ if(BUILD_LIBRARY)
4545

4646
set(MAIN_HEADERS
4747
include/Internal.h
48-
include/DFHack.h
4948
include/DFHackVersion.h
5049
include/BitArray.h
5150
include/ColorText.h

library/LuaApi.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,7 @@ static const LuaWrapper::FunctionReg dfhack_module[] = {
13741374
WRAP(isWorldLoaded),
13751375
WRAP(isMapLoaded),
13761376
WRAP(isSiteLoaded),
1377-
WRAPM(Translation, TranslateName),
1378-
WRAPM(Translation, GenerateName),
1377+
WRAPN(Translation, Translation::translateName), // left for backward compatibility
13791378
WRAP(df2utf),
13801379
WRAP(utf2df),
13811380
WRAP(df2console),
@@ -1405,6 +1404,14 @@ static const luaL_Reg dfhack_funcs[] = {
14051404
{ NULL, NULL }
14061405
};
14071406

1407+
/***** Translation module *****/
1408+
1409+
static const LuaWrapper::FunctionReg dfhack_translation_module[] = {
1410+
WRAPM(Translation, translateName),
1411+
WRAPM(Translation, generateName),
1412+
{ NULL, NULL }
1413+
};
1414+
14081415
/***** Gui module *****/
14091416

14101417
static int gui_getDwarfmodeViewDims(lua_State *state)
@@ -4248,6 +4255,7 @@ void OpenDFHackApi(lua_State *state)
42484255

42494256
LuaWrapper::SetFunctionWrappers(state, dfhack_module);
42504257
luaL_setfuncs(state, dfhack_funcs, 0);
4258+
OpenModule(state, "translation", dfhack_translation_module);
42514259
OpenModule(state, "gui", dfhack_gui_module, dfhack_gui_funcs);
42524260
OpenModule(state, "job", dfhack_job_module, dfhack_job_funcs);
42534261
OpenModule(state, "textures", dfhack_textures_funcs);

library/LuaTools.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ distribution.
4141
#include "modules/Gui.h"
4242
#include "modules/Job.h"
4343
#include "modules/Screen.h"
44-
#include "modules/Translation.h"
4544
#include "modules/Units.h"
4645

4746
#include "df/building.h"

library/PlugLoad.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "Core.h"
2-
#include "DFHack.h"
32
#include "Debug.h"
43
#include "Export.h"
54
#include "PluginManager.h"

library/RemoteTools.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ void DFHack::describeName(NameInfo *info, df::language_name *name)
235235
if (name->language >= 0)
236236
info->set_language_id(name->language);
237237

238-
std::string lname = Translation::TranslateName(name, false, true);
238+
std::string lname = Translation::translateName(name, false, true);
239239
if (!lname.empty())
240240
info->set_last_name(DF2UTF(lname));
241241

242-
lname = Translation::TranslateName(name, true, true);
242+
lname = Translation::translateName(name, true, true);
243243
if (!lname.empty())
244244
info->set_english_name(DF2UTF(lname));
245245
}

library/include/DFHack.h

Lines changed: 0 additions & 78 deletions
This file was deleted.

library/include/modules/Translation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ DFHACK_EXPORT void setNickname(df::language_name *name, std::string nick);
5757
DFHACK_EXPORT std::string capitalize(const std::string &str, bool all_words = false);
5858

5959
// translate a name using the loaded dictionaries
60-
DFHACK_EXPORT std::string TranslateName (const df::language_name * name, bool inEnglish = false,
60+
DFHACK_EXPORT std::string translateName (const df::language_name * name, bool inEnglish = false,
6161
bool onlyLastPart = false);
6262

63-
DFHACK_EXPORT void GenerateName(df::language_name *name, int language_index, df::language_name_type nametype, df::language_word_table *major_selector, df::language_word_table *minor_selector);
63+
DFHACK_EXPORT void generateName(df::language_name *name, int language_index, df::language_name_type nametype,
64+
df::language_word_table *major_selector, df::language_word_table *minor_selector);
6465
}
6566
}
6667
#endif

library/modules/Items.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ static string get_base_desc(df::item *item) {
709709
if (auto name = Items::getBookTitle(item); !name.empty())
710710
return name;
711711
if (auto artifact = get_artifact(item); artifact && artifact->name.has_name)
712-
return Translation::TranslateName(&artifact->name) +
713-
", " + Translation::TranslateName(&artifact->name, true) +
712+
return Translation::translateName(&artifact->name) +
713+
", " + Translation::translateName(&artifact->name, true) +
714714
" (" + get_item_type_str(item) + ")";
715715
return Items::getDescription(item, 0, true);
716716
}

0 commit comments

Comments
 (0)