PermissionScope 本地化的問題

最近這篇文章可火了。33個2017年你必須關注的框架

所以嘗鮮使用了一下 ** PermissionScope **這個框架胞得,好用是挺好用的肩榕,但是有一些地方沒有加上本地化。比如打開某個權限后權限按鈕會變成 下圖這樣子陆盘。這中英文的搭配肯定是不行的啦,偽裝高大上败明。但是看了下代碼和說明隘马,我們只能自定義部分 Label 的文字樣式等等。反正就是無法修改權限按鈕的文本妻顶。但是顏色酸员、字體什么的是可以的。

圖片發(fā)自簡書App

那么怎么修改權限按鈕呢讳嘱。在代碼里搜索一下 ALLOWED 幔嗦,定位到 PermissionScope.swift 的 viewWillLayoutSubviews 方法,里面有一句

button.setTitle("Allowed \(prettyDescription)".localized.uppercased(), for: .normal)

可以看到肯定是這行代碼來給權限按鈕賦值呢燥,然后我們點擊 localized 看看是什么情況崭添,會發(fā)現(xiàn)這是個 String 的 Extension

extension String {
    /// NSLocalizedString shorthand
    var localized: String {
        return NSLocalizedString(self, comment: "")
    }
}

那答案就呼之欲出了,自然是 本地化 啦叛氨。

本地化的步驟和以前我們做的基本上是一樣的呼渣。
1、新建一個 Strings File寞埠,并命名為 Localizable.strings屁置。
2、點擊該文件仁连,在 Xcode 的右側的 File inspection 中點擊 Localize蓝角,這里我們先只點開 Chinese
3阱穗、后面就是賦值了,此處我直接附上所有會用到的 key使鹅,此處參考了 https://github.com/nickoneill/PermissionScope/pull/12#issuecomment-96428580returnpermissionScope

"Allow Contacts" = "";
"Allow Events" = "";
"Enable Location" = "";
"Allow Notifications" = "";
"Allow Microphone" = "";
"Allow Camera" = "";
"Allow Photos" = "";
"Allow Reminders" = "";
"Allow Bluetooth" = "";
"Allow Motion" = "";
//
"Contacts" = "";
"Events" = "";
"LocationAlways" = "";
"LocationInUse" = "";
"Notifications" = "";
"Microphone" = "";
"Camera" = "";
"Photos" = "";
"Reminders" = "";
"Bluetooth" = "";
"Motion" = "";
//
"Allowed Contacts" = "";
"Allowed Events" = "";
"Allowed Location" = "";
"Allowed Notifications" = "";
"Allowed Microphone" = "";
"Allowed Camera" = "";
"Allowed Photos" = "";
"Allowed Reminders" = "";
"Allowed Bluetooth" = "";
"Allowed Motion" = "";
//
"Denied Contacts" = "";
"Denied Events" = "";
"Denied Location" = "";
"Denied Notifications" = "";
"Denied Microphone" = "";
"Denied Camera" = "";
"Denied Photos" = "";
"Denied Reminders" = "";
"Denied Bluetooth" = "";
"Denied Motion" = "";
//
"Contacts Disabled" = "";
"Events Disabled" = "";
"Location Disabled" = "";
"Notifications Disabled" = "";
"Microphone Disabled" = "";
"Camera Disabled" = "";
"Photos Disabled" = "";
"Reminders Disabled" = "";
"Bluetooth Disabled" = "";
"Motion Disabled" = "";

//
"Close" = "";
"Hey, listen!" = "";
"We need a couple things\r\nbefore you get started." = "";
"Permission for Contacts was denied." = "";
"Permission for Events was denied." = "";
"Permission for LocationAlways was denied." = "";
"Permission for LocationInUse was denied." = "";
"Permission for Notifications was denied." = "";
"Permission for Microphone was denied." = "";
"Permission for Camera was denied." = "";
"Permission for Photos was denied." = "";
"Permission for Reminders was denied." = "";
"Permission for Bluetooth was denied." = "";
"Permission for Motion was denied." = "";
//
"Please enable access to Contacts in the Settings app" = "";
"Please enable access to Events in the Settings app" = "";
"Please enable access to LocationAlways in the Settings app" = "";
"Please enable access to LocationInUse in the Settings app" = "";
"Please enable access to Notifications in the Settings app" = "";
"Please enable access to Microphone in the Settings app" = "";
"Please enable access to Camera in the Settings app" = "";
"Please enable access to Photos in the Settings app" = "";
"Please enable access to Reminders in the Settings app" = "";
"Please enable access to Bluetooth in the Settings app" = "";
"Please enable access to Motion in the Settings app" = "";
//
"OK" = "";
"Show me" = "";
//
"Contacts is currently disabled." = "";
"Events is currently disabled." = "";
"LocationAlways is currently disabled." = "";
"LocationInUse is currently disabled." = "";
"Notifications is currently disabled." = "";
"Microphone is currently disabled." = "";
"Camera is currently disabled." = "";
"Photos is currently disabled." = "";
"Reminders is currently disabled." = "";
"Bluetooth is currently disabled." = "";
"Motion is currently disabled." = "";
//
"Please enable access to Contacts in Settings" = "";
"Please enable access to Events in Settings" = "";
"Please enable access to LocationAlways in Settings" = "";
"Please enable access to LocationInUse in Settings" = "";
"Please enable access to Notifications in Settings" = "";
"Please enable access to Microphone in Settings" = "";
"Please enable access to Camera in Settings" = "";
"Please enable access to Photos in Settings" = "";
"Please enable access to Reminders in Settings" = "";
"Please enable access to Bluetooth in Settings" = "";
"Please enable access to Motion in Settings" = "";

好了揪阶,賦值吧。
我們再看看下圖患朱。鲁僚。。其中那個『注意了裁厅、我們需要做一些事情冰沙、我們會使用這個權限』這些字符串是可以在其他的地方進行直接賦值的,這里就不展開了执虹。


圖片發(fā)自簡書App
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末拓挥,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子袋励,更是在濱河造成了極大的恐慌侥啤,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,591評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件茬故,死亡現(xiàn)場離奇詭異愿棋,居然都是意外死亡,警方通過查閱死者的電腦和手機均牢,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,448評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來才睹,“玉大人徘跪,你說我怎么就攤上這事±湃粒” “怎么了垮庐?”我有些...
    開封第一講書人閱讀 162,823評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長坞琴。 經常有香客問我哨查,道長,這世上最難降的妖魔是什么剧辐? 我笑而不...
    開封第一講書人閱讀 58,204評論 1 292
  • 正文 為了忘掉前任寒亥,我火速辦了婚禮,結果婚禮上荧关,老公的妹妹穿的比我還像新娘溉奕。我一直安慰自己,他們只是感情好忍啤,可當我...
    茶點故事閱讀 67,228評論 6 388
  • 文/花漫 我一把揭開白布加勤。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪鳄梅。 梳的紋絲不亂的頭發(fā)上叠国,一...
    開封第一講書人閱讀 51,190評論 1 299
  • 那天,我揣著相機與錄音戴尸,去河邊找鬼粟焊。 笑死,一個胖子當著我的面吹牛校赤,可吹牛的內容都是我干的吆玖。 我是一名探鬼主播,決...
    沈念sama閱讀 40,078評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼马篮,長吁一口氣:“原來是場噩夢啊……” “哼沾乘!你這毒婦竟也來了?” 一聲冷哼從身側響起浑测,我...
    開封第一講書人閱讀 38,923評論 0 274
  • 序言:老撾萬榮一對情侶失蹤翅阵,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后迁央,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體掷匠,經...
    沈念sama閱讀 45,334評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,550評論 2 333
  • 正文 我和宋清朗相戀三年岖圈,在試婚紗的時候發(fā)現(xiàn)自己被綠了讹语。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,727評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡蜂科,死狀恐怖顽决,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情导匣,我是刑警寧澤才菠,帶...
    沈念sama閱讀 35,428評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站贡定,受9級特大地震影響赋访,放射性物質發(fā)生泄漏。R本人自食惡果不足惜缓待,卻給世界環(huán)境...
    茶點故事閱讀 41,022評論 3 326
  • 文/蒙蒙 一蚓耽、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧命斧,春花似錦田晚、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,672評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽芹壕。三九已至,卻和暖如春接奈,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背序宦。 一陣腳步聲響...
    開封第一講書人閱讀 32,826評論 1 269
  • 我被黑心中介騙來泰國打工互捌, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人钳降。 一個月前我還...
    沈念sama閱讀 47,734評論 2 368
  • 正文 我出身青樓遂填,卻偏偏與公主長得像澈蝙,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子礁击,可洞房花燭夜當晚...
    茶點故事閱讀 44,619評論 2 354

推薦閱讀更多精彩內容