Awesome
gms2-mofile
MoFile loader for Gamemaker Studio 2.3+
Table of Contents
- Requirements
- Download
- Maintainers & Contribution
- Samples
- Setup
- Configuration
- Pulling Translation Strings From Code
- API
Requirements
Release Version | Gamemaker Version |
---|---|
1.0.x | v2.3.0.x+ |
1.1.x | v2022.09.x.y+ |
Download
- Download the exported local package
- Select Tools > Import Local Package
- Navigate to the saved package and select import
- Import all resources
Maintainers & Contribution
This package is maintained by Paige Marincak. To contribute, please fork the repo and make pull requests.
Samples
Samples can be viewed here.
Setup
PoEdit Files
- Create a folder in your datafiles called TranslationFiles.
- Copy the sample.po and sample.mo files from the sample to the new folder.
GML
- Add MofileGameStart() to the GameStart of an object that is created at the start of the game.
- Add MofileGameEnd() to the GameEnd of an object that is destroyed at the end of the game.
- Load your mofile at any point after MofileGameStart using MofileLoadLanguageFile("sample.mo")
Configuration
GML
Variable Name | Default Value | Description |
---|---|---|
MOFILE_INCLUDED_FILES_SUBDIRECTORY | "TranslationFiles" | Path to datafiles subdirectory where the mofiles are stored at runtime. |
MOFILE_USE_WORKING_DIRECTORY | true | Whether to preface MOFILE_INCLUDED_FILES_SUBDIRECTORY with the working_directory or not. |
Translation Functions
If you would like to rename _ or _MofileMarkTranslation:
- Rename the functions as preferred in the code. Example: TL and TL_Marker.
- Open your Po File. (i.e. sample.po) Recommend using PoEdit.
- Translation > Properties > Sources keywords
- Change "_" to "TL" and "_MofileMarkTranslation" to "TL_Marker"
- Press Ok.
PoEdit
If you would like to use PoEdit to pull translation strings from your code, you will need to create a custom extractor as follows:
- Open PoEdit.
- File > Preferences > Extractors
- Click the + at the bottom.
- Create the Extractor with the following configuration and click OK:
Name | Value |
---|---|
Language | GML |
Extensions | *.gml |
Extraction Command | xgettext --language=C --add-comments=TRANSLATORS: --force-po -o %o %C %K %F |
Keywords List | -k%k |
Input File List | %f |
Charset | --from-code=%c |
Pulling Translation Strings From Code
- Open your Po File. (i.e. sample.po) Recommend using PoEdit.
- Press Update From Code
- New strings added and removed will be visible
- Save to generate a new MoFile.
API
MofileGameStart
Sets up the linkage between GML and the MoFile DLL. Should be called once at GameStart.
MofileGameEnd
Frees the MoFile DLL. Should be called once at GameEnd.
_
Marks the provided value as a translatable string and returns the translation from the loaded MoFile. Feel free to rename this function to whatever shorthand makes the most sense. Be aware that you will need to update PoEdit grep configurations.
@param {String} value
_MofileMarkTranslation
Marks the provided value as a translatable string and returns the original value. Feel free to rename this function to whatever shorthand makes the most sense. Be aware that you will need to update PoEdit grep configurations.
@param {String} value
MofileLoadLanguageFile
Loads the localization file represented by the provided filename and returns whether it was successful or not.
@param {String} filename