UNPKG

3.26 kBTypeScriptView Raw
1import { Except, SetOptional } from 'type-fest';
2import { BasicMetaSysProps, SysLink, DefaultElements, MakeRequest } from '../common-types';
3export type LocaleProps = {
4 sys: BasicMetaSysProps & {
5 space: SysLink;
6 environment: SysLink;
7 };
8 /**
9 * Locale name
10 */
11 name: string;
12 /**
13 * Locale code (example: en-us)
14 */
15 code: string;
16 /**
17 * Internal locale code
18 */
19 internal_code: string;
20 /**
21 * Locale code to fallback to when there is not content for the current locale
22 */
23 fallbackCode: string | null;
24 /**
25 * If the content under this locale should be available on the CDA (for public reading)
26 */
27 contentDeliveryApi: boolean;
28 /**
29 * If the content under this locale should be available on the CMA (for editing)
30 */
31 contentManagementApi: boolean;
32 /**
33 * If this is the default locale
34 */
35 default: boolean;
36 /**
37 * If the locale needs to be filled in on entries or not
38 */
39 optional: boolean;
40};
41export type CreateLocaleProps = Omit<SetOptional<Except<LocaleProps, 'sys'>, 'optional' | 'contentManagementApi' | 'default' | 'contentDeliveryApi'>, 'internal_code'>;
42export interface Locale extends LocaleProps, DefaultElements<LocaleProps> {
43 /**
44 * Deletes this object on the server.
45 * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
46 * @example ```javascript
47 * const contentful = require('contentful-management')
48 *
49 * const client = contentful.createClient({
50 * accessToken: '<content_management_api_key>'
51 * })
52 *
53 * client.getSpace('<space_id>')
54 * .then((space) => space.getEnvironment('<environment_id>'))
55 * .then((environment) => environment.getLocale('<locale_id>'))
56 * .then((locale) => locale.delete())
57 * .then(() => console.log(`locale deleted.`))
58 * .catch(console.error)
59 * ```
60 */
61 delete(): Promise<void>;
62 /**
63 * Sends an update to the server with any changes made to the object's properties
64 * @return Object returned from the server with updated changes.
65 * @example ```javascript
66 * const contentful = require('contentful-management')
67 *
68 * const client = contentful.createClient({
69 * accessToken: '<content_management_api_key>'
70 * })
71 *
72 * client.getSpace('<space_id>')
73 * .then((space) => space.getEnvironment('<environment_id>'))
74 * .then((environment) => environment.getLocale('<locale_id>'))
75 * .then((locale) => {
76 * locale.name = 'New locale name'
77 * return locale.update()
78 * })
79 * .then((locale) => console.log(`locale ${locale.sys.id} updated.`))
80 * .catch(console.error)
81 * ```
82 */
83 update(): Promise<Locale>;
84}
85/**
86 * @private
87 * @param makeRequest - function to make requests via an adapter
88 * @param data - Raw locale data
89 * @return Wrapped locale data
90 */
91export declare function wrapLocale(makeRequest: MakeRequest, data: LocaleProps): Locale;
92/**
93 * @private
94 */
95export declare const wrapLocaleCollection: (makeRequest: MakeRequest, data: import("../common-types").CollectionProp<LocaleProps>) => import("../common-types").Collection<Locale, LocaleProps>;