[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 7e7d6cd 09/17: Start collecting random internation
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 7e7d6cd 09/17: Start collecting random internationalized methods |
Date: |
Tue, 26 Sep 2017 17:15:34 -0400 (EDT) |
branch: externals/ebdb
commit 7e7d6cd326d7d825ac55604774f7d3319f4f03c3
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Start collecting random internationalized methods
* ebdb-i18n-basic.el: New file, where I'll put everything that occurs
to me. If and as country-specific libraries are developed, the
relevant methods can be removed from this file.
* ebdb-i18n.el: Require the above file.
---
ebdb-i18n-basic.el | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++
ebdb-i18n.el | 1 +
2 files changed, 212 insertions(+)
diff --git a/ebdb-i18n-basic.el b/ebdb-i18n-basic.el
new file mode 100644
index 0000000..892305c
--- /dev/null
+++ b/ebdb-i18n-basic.el
@@ -0,0 +1,211 @@
+;;; ebdb-i18n-basic.el --- Basic internationalization methods for EBDB -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Eric Abrahamsen <address@hidden>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file provides internationalized methods for a few common
+;; countries, "common" here meaning what used to be in
+;; `ebdb-address-format-list'.
+
+;;; Code:
+
+;;; USA
+
+(defvar ebdb-i18n-usa-states
+ '(("Alabama" . "AL")
+ ("Alaska" . "AK")
+ ("American Samoa " . "AS")
+ ("Arizona" . "AZ")
+ ("Arkansas" . "AR")
+ ("California" . "CA")
+ ("Colorado" . "CO")
+ ("Connecticut" . "CT")
+ ("Delaware" . "DE")
+ ("Dist. of Columbia" . "DC")
+ ("Florida" . "FL")
+ ("Georgia" . "GA")
+ ("Guam" . "GU")
+ ("Hawaii" . "HI")
+ ("Idaho" . "ID")
+ ("Illinois" . "IL")
+ ("Indiana" . "IN")
+ ("Iowa" . "IA")
+ ("Kansas" . "KS")
+ ("Kentucky" . "KY")
+ ("Louisiana" . "LA")
+ ("Maine" . "ME")
+ ("Maryland" . "MD")
+ ("Marshall Islands" . "MH")
+ ("Massachusetts" . "MA")
+ ("Michigan" . "MI")
+ ("Micronesia" . "FM")
+ ("Minnesota" . "MN")
+ ("Mississippi" . "MS")
+ ("Missouri" . "MO")
+ ("Montana" . "MT")
+ ("Nebraska" . "NE")
+ ("Nevada" . "NV")
+ ("New Hampshire" . "NH")
+ ("New Jersey" . "NJ")
+ ("New Mexico" . "NM")
+ ("New York" . "NY")
+ ("North Carolina" . "NC")
+ ("North Dakota" . "ND")
+ ("Northern Marianas" . "MP")
+ ("Ohio" . "OH")
+ ("Oklahoma" . "OK")
+ ("Oregon" . "OR")
+ ("Palau" . "PW")
+ ("Pennsylvania" . "PA")
+ ("Puerto Rico" . "PR")
+ ("Rhode Island" . "RI")
+ ("South Carolina" . "SC")
+ ("South Dakota" . "SD")
+ ("Tennessee" . "TN")
+ ("Texas" . "TX")
+ ("Utah" . "UT")
+ ("Vermont" . "VT")
+ ("Virginia" . "VA")
+ ("Virgin Islands" . "VI")
+ ("Washington" . "WA")
+ ("West Virginia" . "WV")
+ ("Wisconsin" . "WI")
+ ("Wyoming" . "WY"))
+ "All the states in the US, for use with completion.")
+
+(cl-defmethod ebdb-string-i18n ((phone ebdb-field-phone)
+ (_cc (eql 1)))
+ (with-slots (area-code number extension) phone
+ (format "+1 (%d) %s-%s%s"
+ area-code
+ (substring number 0 3)
+ (substring number 3)
+ (if extension (format "X%d" extension) ""))))
+
+(cl-defmethod ebdb-read-i18n ((_class (subclass ebdb-field-address))
+ (_cc (eql usa))
+ &optional slots obj)
+ (unless (plist-member slots :region)
+ (setq slots
+ (plist-put
+ slots :region
+ (cdr (assoc-string
+ (ebdb-read-string
+ "State: "
+ (when obj (ebdb-address-region obj))
+ ebdb-i18n-usa-states t)
+ ebdb-i18n-usa-states)))))
+ slots)
+
+(cl-defmethod ebdb-parse-i18n ((_class (subclass ebdb-field-address))
+ (str string)
+ (_cc (eql usa))
+ &optional slots)
+ (let ((states (mapcar #'cdr ebdb-i18n-usa-states)))
+ (unless (plist-member slots :country)
+ (setq slots (plist-put slots :country 'usa)))
+ (with-temp-buffer
+ (insert str)
+ (when (re-search-backward
"[[:digit:]]\\{5\\}\\(?:-[[:digit:]]\\{4\\}\\)?"
+ nil t)
+ (setq slots (plist-put slots :postcode (match-string 0))))
+ (when (re-search-backward (concat "\\(" (regexp-opt states) "\\)[ ,]+")
+ (line-beginning-position) t)
+ (setq slots (plist-put slots :region (match-string 1))))
+ (when (re-search-backward "\\(?:^\\|, \\)\\([[:alpha:].-]+
?[[:alpha:].-]+\\)[ ,]+"
+ (line-beginning-position) t)
+ (setq slots (plist-put slots :locality (match-string 1))))
+ (setq slots (plist-put slots :streets
+ (split-string (buffer-substring (point-min)
(point))
+ "[,\n]" t))))
+ slots))
+
+;;; France
+
+(cl-defmethod ebdb-string-i18n ((phone ebdb-field-phone)
+ (_cc (eql 33)))
+ (with-slots (area-code number extension) phone
+ (concat
+ "+33 "
+ (when area-code
+ (format "%02d" area-code))
+ (apply #'format "%s%s %s%s %s%s %s%s"
+ (split-string number "" t))
+ (when extension
+ (format "X%d" extension)))))
+
+;;; UK
+
+(cl-defmethod ebdb-read-i18n ((_class (subclass ebdb-field-address))
+ (_cc (eql gbr))
+ &optional slots _obj)
+ "UK addresses don't need a region."
+ (plist-put slots :region ""))
+
+;;; India
+
+(defvar ebdb-i18n-india-states
+ '("Andhra Pradesh"
+ "Arunachal Pradesh"
+ "Assam"
+ "Bihar"
+ "Chhattisgarh"
+ "Goa"
+ "Gujarat"
+ "Haryana"
+ "Himachal Pradesh"
+ "Jammu and Kashmir"
+ "Jharkhand"
+ "Karnataka"
+ "Kerala"
+ "Madhya Pradesh"
+ "Maharashtra"
+ "Manipur"
+ "Meghalaya"
+ "Mizoram"
+ "Nagaland"
+ "Odisha"
+ "Punjab"
+ "Rajasthan"
+ "Sikkim"
+ "Tamil Nadu"
+ "Telangana"
+ "Tripura"
+ "Uttar Pradesh"
+ "Uttarakhand"
+ "West Bengal")
+ "A list of states in India, for completion.")
+
+(cl-defmethod ebdb-read-i18n ((_class (subclass ebdb-field-address))
+ (_cc (eql ind))
+ &optional slots obj)
+ (unless (plist-member slots :region)
+ (setq slots
+ (plist-put
+ slots :region
+ (cdr (assoc-string
+ (ebdb-read-string
+ "State: "
+ (when obj (ebdb-address-region obj))
+ ebdb-i18n-india-states t)
+ ebdb-i18n-india-states)))))
+ slots)
+
+(provide 'ebdb-i18n-basic)
+;;; ebdb-i18n-basic.el ends here
diff --git a/ebdb-i18n.el b/ebdb-i18n.el
index 9d6c9d1..5dc26a3 100644
--- a/ebdb-i18n.el
+++ b/ebdb-i18n.el
@@ -42,6 +42,7 @@
;;; Code:
(require 'ebdb)
+(require 'ebdb-i18n-basic)
(defgroup ebdb-i18n nil
"Options for EBDB internationalization."
- [elpa] externals/ebdb 2a17bb6 03/17: Set up EBDB buffers to offer save on save-some-buffers, (continued)
- [elpa] externals/ebdb 2a17bb6 03/17: Set up EBDB buffers to offer save on save-some-buffers, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 26d632b 05/17: Finish ebdb-internationalize-addresses, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 3f1eb0d 04/17: New defsubst ebdb-i18n-countries, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb f143265 07/17: Quietly swap order of arguments to ebdb-read-i18n for addresses, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 880be9f 14/17: Fix to dumb mistakes in 8fc7b6d69, fast lookups, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb b371784 15/17: Change ebdb-vcard to use generic ebdb-field-tags, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb c5aac30 01/17: Change name of automatic save option, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb fb7e4d2 11/17: Add formatting for Russian phone numbers, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb e947f59 06/17: Drop postcode guards, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb e78dd19 10/17: Provide an ebdb-parse method for addresses, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 7e7d6cd 09/17: Start collecting random internationalized methods,
Eric Abrahamsen <=
- [elpa] externals/ebdb e326805 08/17: Simplify address formatting, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 4f8e2a0 16/17: Use ebdb-i18n-countries defsubst in i18n address reading, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 91d73f8 17/17: Bump version to 0.3.3, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb 7c16983 12/17: Fix all when-let and if-let to use starred versions, Eric Abrahamsen, 2017/09/26
- [elpa] externals/ebdb bd7b45a 13/17: Revert "Use value of ebdb-mua-folder-list in VM splitting", Eric Abrahamsen, 2017/09/26