Skip to content

Commit

Permalink
Add support for localized message transalations in MacVim
Browse files Browse the repository at this point in the history
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 macvim-dev#991
  • Loading branch information
ychin committed Aug 10, 2020
1 parent a530cca commit 6a0ac01
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ env:

_anchors:
- &lang_env
env: LANGOPT="--enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic --enable-luainterp=dynamic --with-lua-prefix=/usr/local"
env:
- LANGOPT="--enable-perlinterp=dynamic --enable-pythoninterp=dynamic --enable-python3interp=dynamic --enable-rubyinterp=dynamic --enable-luainterp=dynamic --with-lua-prefix=/usr/local"
HAS_GETTEXT=1
- &homebrew
addons:
homebrew:
packages:
- gettext
- lua
- python
- ruby
Expand Down Expand Up @@ -64,6 +67,7 @@ script:
- set +o errexit
- ${VIMCMD} --version
- echo -e "\\033[33;1mTesting MacVim\\033[0m" && echo -en "travis_fold:start:test\\r\\033[0K"
# Smoketest scripting languages
- |
macvim_excmd() {
if [[ -n "${LANGOPT}" ]]; then
Expand All @@ -75,6 +79,12 @@ script:
- macvim_excmd -c 'py import sys; print("Test")'
- macvim_excmd -c 'py3 import sys; print("Test")'
- macvim_excmd -c 'ruby puts("Test")'
# Check that localized messages work by printing ':version' and checking against localized word
- |
if [[ -n "${HAS_GETTEXT}" ]]; then
${VIMCMD} -es -c 'lang es_ES' -c 'redir @a' -c 'version' -c 'put a' -c 'print' -c 'qa!' | grep Enlazado
fi
# Run standard test suites
- make test
- make -C runtime/doc vimtags VIMEXE=../../src/MacVim/build/Release/MacVim.app/Contents/bin/vim
- echo -en "travis_fold:end:test\\r\\033[0K"
Expand Down
20 changes: 20 additions & 0 deletions src/MacVim/MacVim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@
1D9EB2840C366D7B0074B739 /* Copy Frameworks */,
52818B021C1C088000F59085 /* Copy QuickLookPlugin */,
1DE608B80C58807F0055263D /* Copy Vim Runtime Files */,
90BD4EF224E0E8B700BF29F2 /* Copy locale message translation files */,
1D1C31F00EFFBFD6003FE9A5 /* Make Document Icons */,
528DA6671426D456003380F1 /* Copy Scripts */,
52283AB71EBA200C00A6F6B9 /* Copy mvim scripts */,
Expand Down Expand Up @@ -983,6 +984,25 @@
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";
showEnvVarsInLog = 0;
};
90BD4EF224E0E8B700BF29F2 /* Copy locale message translation files */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Copy locale message translation files";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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/share/local/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";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
8 changes: 7 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3745,7 +3745,7 @@ $(APPDIR)/Contents:

##############################################################################
### MacVim GUI
.PHONY: macvim macvim-dmg macvimclean macvim-signed macvim-dmg-release
.PHONY: macvim macvim-dmg macvimclean macvim-signed macvim-dmg-release macvim-install-languages

RELEASEDIR = MacVim/build/Release
DMGDIR = MacVim/build/dmg
Expand Down Expand Up @@ -3785,6 +3785,12 @@ macvim-dmg-release: macvim-signed macvim-dmg
echo "--------------------"
echo "Release MacVim built!"

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

# Dependencies that "make depend" doesn't find
objects/gui_gtk_x11.o: version.h
Expand Down
6 changes: 6 additions & 0 deletions src/vim.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
# define _(x) ((char *)(x))
# define NGETTEXT(x, xs, n) (((n) == 1) ? (char *)(x) : (char *)(xs))
# define N_(x) x
#ifdef FEAT_GUI_MACVIM
// In MacVim, we want bindtextdomain to work because we bundle the locale
// files in runtime dir instead of a global install loation. This is
// similar to Windows (which has DYNAMIC_GETTEXT set).
#else
# ifdef bindtextdomain
# undef bindtextdomain
# endif
Expand All @@ -563,6 +568,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
# undef textdomain
# endif
# define textdomain(x) // empty
#endif // MacVim
#endif

/*
Expand Down

0 comments on commit 6a0ac01

Please sign in to comment.