Skip to content

Commit c27ef2a

Browse files
committed
Add support for localized message transalations in MacVim
This enables localized translated messages in MacVim, instead of only using English. - Get Travis to compile MacVim with gettext dependencies which is a pre-requisite for multilang localized messages. Also add a quick regression test to make sure localized messages will keep working. - Add a post-build phase to copy all locale .mo files to VIMRUNTIME/lang so they will be bundled along with the rest in the app package. Normal Vim usually installs the localized files to a global location like /usr/local/share/locale/ but macOS applications are all self-contained bundles we don't want to do this. Use VIMRUNTIME/lang as the destination because that's also what the Windows build uses and existing code already knows to use it by using bindtextdomain. - Fix vim.h header to not unbind bindtextdomain for MacVim. There is previously a little bit of hack there where it would only use bindtextdomain when DYNAMIC_GETTEXT is set because that's only set for Windows. Just add a special case for MacVim for now to get similar behavior to Windows. Close #991
1 parent a530cca commit c27ef2a

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ env:
2323

2424
_anchors:
2525
- &lang_env
26-
env: LANGOPT="--enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic --enable-luainterp=dynamic --with-lua-prefix=/usr/local"
26+
env:
27+
- LANGOPT="--enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic --enable-luainterp=dynamic --with-lua-prefix=/usr/local"
28+
HAS_GETTEXT=1
2729
- &homebrew
2830
addons:
2931
homebrew:
3032
packages:
33+
- gettext
3134
- lua
3235
- python
3336
- ruby
@@ -64,6 +67,7 @@ script:
6467
- set +o errexit
6568
- ${VIMCMD} --version
6669
- echo -e "\\033[33;1mTesting MacVim\\033[0m" && echo -en "travis_fold:start:test\\r\\033[0K"
70+
# Smoketest scripting languages
6771
- |
6872
macvim_excmd() {
6973
if [[ -n "${LANGOPT}" ]]; then
@@ -75,6 +79,12 @@ script:
7579
- macvim_excmd -c 'py import sys; print("Test")'
7680
- macvim_excmd -c 'py3 import sys; print("Test")'
7781
- macvim_excmd -c 'ruby puts("Test")'
82+
# Check that localized messages work by printing ':version' and checking against localized word
83+
- |
84+
if [[ -n "${HAS_GETTEXT}" ]]; then
85+
${VIMCMD} -es -c 'lang es_ES' -c 'redir @a' -c 'version' -c 'put a' -c 'print' -c 'qa!' | grep Enlazado
86+
fi
87+
# Run standard test suites
7888
- make test
7989
- make -C runtime/doc vimtags VIMEXE=../../src/MacVim/build/Release/MacVim.app/Contents/bin/vim
8090
- echo -en "travis_fold:end:test\\r\\033[0K"

src/MacVim/MacVim.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@
836836
1D9EB2840C366D7B0074B739 /* Copy Frameworks */,
837837
52818B021C1C088000F59085 /* Copy QuickLookPlugin */,
838838
1DE608B80C58807F0055263D /* Copy Vim Runtime Files */,
839+
90BD4EF224E0E8B700BF29F2 /* Copy locale message translation files */,
839840
1D1C31F00EFFBFD6003FE9A5 /* Make Document Icons */,
840841
528DA6671426D456003380F1 /* Copy Scripts */,
841842
52283AB71EBA200C00A6F6B9 /* Copy mvim scripts */,
@@ -983,6 +984,25 @@
983984
shellScript = "BINPATH=$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/bin\nmkdir -p \"${BINPATH}\"\ncp -a \"${SRCROOT}/mvim\" \"${BINPATH}/mvim\"\nchmod 755 \"${BINPATH}/mvim\"\n(cd \"${BINPATH}\"; for f in vim vimdiff view gvim gvimdiff gview mvimdiff mview; do ln -fs mvim $f; done)\n";
984985
showEnvVarsInLog = 0;
985986
};
987+
90BD4EF224E0E8B700BF29F2 /* Copy locale message translation files */ = {
988+
isa = PBXShellScriptBuildPhase;
989+
buildActionMask = 2147483647;
990+
files = (
991+
);
992+
inputFileListPaths = (
993+
);
994+
inputPaths = (
995+
);
996+
name = "Copy locale message translation files";
997+
outputFileListPaths = (
998+
);
999+
outputPaths = (
1000+
);
1001+
runOnlyForDeploymentPostprocessing = 0;
1002+
shellPath = /bin/sh;
1003+
shellScript = "# Copy all the locale translation files from the po folder to\n# runtime/lang/<lang>/LC_MESSAGES/vim.mo. Need to do this because unlike normal\n# Vim, MacVim is distributed as a standalone app package and therefore we don't\n# want to install these files to a global location (e.g.\n# /usr/local/share/locale/). This is similar to how Windows installation\n# (po/Make_mvc.mak) works.\ncd \"${SRCROOT}\"/..\nmake macvim-install-languages DEST_LANG=\"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/vim/runtime/lang\"\n";
1004+
showEnvVarsInLog = 0;
1005+
};
9861006
/* End PBXShellScriptBuildPhase section */
9871007

9881008
/* Begin PBXSourcesBuildPhase section */

src/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3745,7 +3745,7 @@ $(APPDIR)/Contents:
37453745

37463746
##############################################################################
37473747
### MacVim GUI
3748-
.PHONY: macvim macvim-dmg macvimclean macvim-signed macvim-dmg-release
3748+
.PHONY: macvim macvim-dmg macvimclean macvim-signed macvim-dmg-release macvim-install-languages
37493749

37503750
RELEASEDIR = MacVim/build/Release
37513751
DMGDIR = MacVim/build/dmg
@@ -3785,6 +3785,12 @@ macvim-dmg-release: macvim-signed macvim-dmg
37853785
echo "--------------------"
37863786
echo "Release MacVim built!"
37873787

3788+
# Install only language files to a dest folder. Subset of "install-languages".
3789+
macvim-install-languages:
3790+
@if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \
3791+
cd $(PODIR); $(MAKE) prefix=$(DESTDIR)$(prefix) LOCALEDIR=$(DEST_LANG) \
3792+
INSTALL_DATA=$(INSTALL_DATA) FILEMOD=$(FILEMOD) install; \
3793+
fi
37883794

37893795
# Dependencies that "make depend" doesn't find
37903796
objects/gui_gtk_x11.o: version.h

src/vim.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
551551
# define _(x) ((char *)(x))
552552
# define NGETTEXT(x, xs, n) (((n) == 1) ? (char *)(x) : (char *)(xs))
553553
# define N_(x) x
554+
#ifdef FEAT_GUI_MACVIM
555+
// In MacVim, we want bindtextdomain to work because we bundle the locale
556+
// files in runtime dir instead of a global install loation. This is
557+
// similar to Windows (which has DYNAMIC_GETTEXT set).
558+
#else
554559
# ifdef bindtextdomain
555560
# undef bindtextdomain
556561
# endif
@@ -563,6 +568,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
563568
# undef textdomain
564569
# endif
565570
# define textdomain(x) // empty
571+
#endif // MacVim
566572
#endif
567573

568574
/*

0 commit comments

Comments
 (0)