Archive for the 'NSLengthFormatter' Category

2016/01/14 ローカライズドな度量衡表示(長さ)

Cocoaの機能を用いて、ローカライズされた(英語、日本語などの言語環境を考慮した)度量衡の表示を行うAppleScriptです。

AppleScript名:ASOCでローカライズドな度量衡表示(長さ)
– Created 2015-11-20 by Shane Stanley
– Modified 2016-01-14 by Takaaki Naganoya
– 2016 Piyomaru Software
use AppleScript version “2.4″
use scripting additions
use framework “Foundation”

–Length

set engLFormatter to current application’s NSLengthFormatter’s alloc()’s init()
engLFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:“en-US”)
engLFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) –NSFormattingUnitStyleShort, NSFormattingUnitStyleMedium, NSFormattingUnitStyleLong

set a1Res to (engLFormatter’s stringFromMeters:85) as string –m
–>  ”92.956 yards”
set a2Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMillimeter)) as string –mm
–>  ”1 millimeter”
set a3Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitCentimeter)) as string –cm
–>  ”1 centimeter”
set a4Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMeter)) as string –m
–>  ”1 meter”
set a5Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitKilometer)) as string –Km
–>  ”1 kilometer”
set a6Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitInch)) as string –inch
–>  ”1 inch”
set a7Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitFoot)) as string –feet
–>  ”1 foot”
set a8Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitYard)) as string –Yard
–>  ”1 yard”
set a9Res to (engLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMile)) as string –Mile
–>  ”1 mile”

set jpnLFormatter to current application’s NSLengthFormatter’s alloc()’s init()
jpnLFormatter’s numberFormatter()’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:“ja”)
jpnLFormatter’s setUnitStyle:(current application’s NSFormattingUnitStyleLong) –NSFormattingUnitStyleShort, NSFormattingUnitStyleMedium, NSFormattingUnitStyleLong

set j1Res to (jpnLFormatter’s stringFromMeters:85) as string –m
–>  ”85メートル”
set j2Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMillimeter)) as string –mm
–>  ”1ミリメートル”
set j3Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitCentimeter)) as string –cm
–>  ”1センチメートル”
set j4Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMeter)) as string –m
–>  ”1メートル”
set j5Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitKilometer)) as string –Km
–>  ”1キロメートル”
set j6Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitInch)) as string –inch
–>  ”1インチ”
set j7Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitFoot)) as string –feet
–>  ”1フィート”
set j8Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitYard)) as string –Yard
–>  ”1ヤード”
set j9Res to (jpnLFormatter’s stringFromValue:1 unit:(current application’s NSLengthFormatterUnitMile)) as string –Mile
–>  ”1マイル”

★Click Here to Open This Script