PipeWire 0.3.65
spa/include/spa/support/i18n.h
Go to the documentation of this file.
1/* Simple Plugin API
2 *
3 * Copyright © 2021 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef SPA_I18N_H
26#define SPA_I18N_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <spa/utils/hook.h>
33#include <spa/utils/defs.h>
34
44#define SPA_TYPE_INTERFACE_I18N SPA_TYPE_INFO_INTERFACE_BASE "I18N"
45
46#define SPA_VERSION_I18N 0
47struct spa_i18n { struct spa_interface iface; };
48
49struct spa_i18n_methods {
50#define SPA_VERSION_I18N_METHODS 0
51 uint32_t version;
52
60 const char *(*text) (void *object, const char *msgid);
61
71 const char *(*ntext) (void *object, const char *msgid,
72 const char *msgid_plural, unsigned long int n);
73};
74
76static inline const char *
77spa_i18n_text(struct spa_i18n *i18n, const char *msgid)
78{
79 const char *res = msgid;
80 if (SPA_LIKELY(i18n != NULL))
81 spa_interface_call_res(&i18n->iface,
82 struct spa_i18n_methods, res,
83 text, 0, msgid);
84 return res;
86
87static inline const char *
88spa_i18n_ntext(struct spa_i18n *i18n, const char *msgid,
89 const char *msgid_plural, unsigned long int n)
90{
91 const char *res = n == 1 ? msgid : msgid_plural;
92 if (SPA_LIKELY(i18n != NULL))
94 struct spa_i18n_methods, res,
95 ntext, 0, msgid, msgid_plural, n);
96 return res;
97}
98
103#ifdef __cplusplus
104} /* extern "C" */
105#endif
106
107#endif /* SPA_I18N_H */
spa/utils/defs.h
SPA_FORMAT_ARG_FUNC(1) const char *pw_gettext(const char *msgid)
static const char * spa_i18n_ntext(struct spa_i18n *i18n, const char *msgid, const char *msgid_plural, unsigned long int n)
Definition: spa/include/spa/support/i18n.h:96
static const char * spa_i18n_text(struct spa_i18n *i18n, const char *msgid)
Definition: spa/include/spa/support/i18n.h:85
#define spa_interface_call_res(iface, method_type, res, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition: hook.h:255
#define SPA_LIKELY(x)
Definition: defs.h:361
spa/utils/hook.h
Definition: spa/include/spa/support/i18n.h:56
uint32_t version
Definition: spa/include/spa/support/i18n.h:59
Definition: spa/include/spa/support/i18n.h:54
struct spa_interface iface
Definition: spa/include/spa/support/i18n.h:54
Definition: hook.h:158