Created
November 28, 2016 06:41
-
-
Save nicorikken/781efbec51e188cce1da1ca10df76e02 to your computer and use it in GitHub Desktop.
Getting translation layer with po-mode to work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> SPC m | |
SPC m is undefined | |
> , | |
Can't find d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; private/translation/funcs.el | |
;; Functions originate from: https://www.emacswiki.org/emacs/PoMode | |
(when (configuration-layer/package-usedp 'po-mode) | |
(defun po-wrap () | |
"Filter current po-mode buffer through `msgcat' tool to wrap all lines." | |
(interactive) | |
(if (eq major-mode 'po-mode) | |
(let ((tmp-file (make-temp-file "po-wrap.")) | |
(tmp-buf (generate-new-buffer "*temp*"))) | |
(unwind-protect | |
(progn | |
(write-region (point-min) (point-max) tmp-file nil 1) | |
(if (zerop | |
(call-process | |
"msgcat" nil tmp-buf t (shell-quote-argument tmp-file))) | |
(let ((saved (point)) | |
(inhibit-read-only t)) | |
(delete-region (point-min) (point-max)) | |
(insert-buffer tmp-buf) | |
(goto-char (min saved (point-max)))) | |
(with-current-buffer tmp-buf | |
(error (buffer-string))))) | |
(kill-buffer tmp-buf) | |
(delete-file tmp-file))))) | |
(defun po-guess-language () | |
"Return the language related to this PO file." | |
(save-excursion | |
(goto-char (point-min)) | |
(re-search-forward po-any-msgstr-block-regexp) | |
(goto-char (match-beginning 0)) | |
(if (re-search-forward | |
"\n\"Language: +\\(.+\\)\\\\n\"$" | |
(match-end 0) t) | |
(po-match-string 1)))) | |
(defadvice po-edit-string (around setup-spell-checking (string type expand-tabs) activate) | |
"Set up spell checking in subedit buffer." | |
(let ((po-language (po-guess-language))) | |
ad-do-it | |
(if po-language | |
(progn | |
(ispell-change-dictionary po-language) | |
(turn-on-flyspell) | |
(flyspell-buffer)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; private/translation/packages.el | |
(defconst translation-packages | |
'(po-mode | |
(mo-mode :location local))) | |
;;(defun translation/post-init-company() | |
;; (spacemacs|add-company-hook po-mode)) | |
(defun translation/init-po-mode () | |
(use-package po-mode | |
:mode ("\\.po\\'" . po-mode) | |
:defer t | |
:config | |
(progn | |
(add-hook 'po-subedit-mode-hook '(lambda () (longlines-mode 1))) | |
(add-hook 'po-subedit-exit-hook '(lambda () (longlines-mode 0))) | |
;;TODO the keybindings do not seem to work, despite it being similarly | |
;;structured as the Markdown mode. | |
;; Declare prefixes and bind keys | |
(dolist (prefix '(("ml" . "language") | |
("me" . "edit") | |
("ms" . "search") | |
("mc" . "command"))) | |
(spacemacs/declare-prefix-for-mode | |
'po-mode (car prefix) (cdr prefix))) | |
(spacemacs/set-leader-keys-for-major-mode 'po-mode | |
;;command | |
"e" 'po-edit-msgstr | |
"cV" 'po-validate)))) | |
(defun translation/init-mo-mode () | |
(use-package mo-mode | |
:mode ("\\.g?mo\\'" . mo-mode)) | |
(modify-coding-system-alist 'file "\\.g?mo\\'" 'raw-text-unix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment