11import { Endpoint } from '../endpoint'
22import { EndpointClient , EndpointClientConfig } from '../endpoint-client'
3+ import { LocaleTag } from '../types'
34import { PreferenceType } from './devices'
45
56
7+ /**
8+ * The ID of the preference
9+ * @pattern ^[[a-z]*([A-Z][a-z]*)*]{1,36}$
10+ */
11+ export type PreferenceId = string
12+
613export interface DevicePreferenceCore {
714 /**
815 * An alphanumeric English language name for this preference. Will be appended to a namespace
@@ -132,9 +139,33 @@ export type DevicePreferenceCreate = DevicePreferenceBase & {
132139}
133140
134141export type DevicePreference = DevicePreferenceBase & {
135- preferenceId : string
142+ preferenceId : PreferenceId
136143}
137144
145+ export interface PreferenceLocalization {
146+ /** The tag of the locale as defined in [RFC bcp47](http://www.rfc-editor.org/rfc/bcp/bcp47.txt). */
147+ tag : LocaleTag
148+
149+ /**
150+ * A localized label for the Preference
151+ * @example Sensibilité au mouvement
152+ */
153+ label : string
154+
155+ /**
156+ * A localized description of the Preference
157+ * @example Sensibilité au mouvement
158+ */
159+ description ?: string
160+
161+ /**
162+ * Map of an option name to localizations. Options can only be provided
163+ * to localize Enumeration type Preferences, and are required for Enumerations.
164+ * The number of options in a Preference Localization must match the number
165+ * of options in the Preference.
166+ */
167+ options ?: Record < string , { label : string } >
168+ }
138169
139170export class DevicePreferencesEndpoint extends Endpoint {
140171 constructor ( config : EndpointClientConfig ) {
@@ -145,7 +176,7 @@ export class DevicePreferencesEndpoint extends Endpoint {
145176 return this . client . getPagedItems < DevicePreference > ( '' , namespace ? { namespace } : { } )
146177 }
147178
148- public get ( id : string ) : Promise < DevicePreference > {
179+ public get ( id : PreferenceId ) : Promise < DevicePreference > {
149180 return this . client . get ( id )
150181 }
151182
@@ -154,7 +185,15 @@ export class DevicePreferencesEndpoint extends Endpoint {
154185 return this . client . post ( undefined , devicePreference )
155186 }
156187
157- public update ( id : string , devicePreferences : DevicePreference ) : Promise < DevicePreference > {
158- return this . client . put ( id , devicePreferences )
188+ public update ( id : PreferenceId , devicePreference : DevicePreference ) : Promise < DevicePreference > {
189+ return this . client . put ( id , devicePreference )
190+ }
191+
192+ public createLocalization ( preferenceId : PreferenceId , localization : PreferenceLocalization ) : Promise < PreferenceLocalization > {
193+ return this . client . post ( `${ preferenceId } /i18n` , localization )
194+ }
195+
196+ public getLocalization ( preferenceId : PreferenceId , locale : LocaleTag ) : Promise < PreferenceLocalization > {
197+ return this . client . get ( `${ preferenceId } /i18n/${ locale } ` )
159198 }
160199}
0 commit comments