Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created December 12, 2020 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svetlyak40wt/2a9b381770fd3b3578e62d744f2f74e3 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/2a9b381770fd3b3578e62d744f2f74e3 to your computer and use it in GitHub Desktop.
An example how to get user's preferred language on OSX and Windows using LispWorks.
#+cocoa
(defun current-language ()
(let ((lang (objc:with-autorelease-pool ()
(objc:invoke-into
'string
(objc:invoke
(objc:invoke "NSUserDefaults" "standardUserDefaults")
"objectForKey:" "AppleLanguages")
"objectAtIndex:" 0))))
;; 2019-04-29
;; lang can be either on the short form "sv" or the long form "sv-SE".
;; It may have changed in later versions of macOS.
;; Anyway, make sure that this function returns on the short form "sv".
(if (and (= (length lang) 5)
(eq (char lang 2) #\-))
(subseq lang 0 2)
lang)
)
)
#+win32
(fli:define-foreign-function (get-system-default-language-id "GetSystemDefaultLangID")
() :result-type :int)
#+win32
(defun current-language ()
;; Map language id to code - a complete list is available in the Windows documentation of GetSystemDefaultLangID
(case (mod (get-system-default-language-id) 1024) ; we are only interested in the primary language, which resides in the last 10 bits
(#x16 "pt")
(#x1D "sv")
(t "default")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment