PipeWire  0.3.66
spa/include/spa/support/i18n.h
Go to the documentation of this file.
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef SPA_I18N_H
6 #define SPA_I18N_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <spa/utils/hook.h>
13 #include <spa/utils/defs.h>
14 
24 #define SPA_TYPE_INTERFACE_I18N SPA_TYPE_INFO_INTERFACE_BASE "I18N"
25 
26 #define SPA_VERSION_I18N 0
27 struct spa_i18n { struct spa_interface iface; };
28 
29 struct spa_i18n_methods {
30 #define SPA_VERSION_I18N_METHODS 0
31  uint32_t version;
32 
40  const char *(*text) (void *object, const char *msgid);
41 
51  const char *(*ntext) (void *object, const char *msgid,
52  const char *msgid_plural, unsigned long int n);
53 };
54 
56 static inline const char *
57 spa_i18n_text(struct spa_i18n *i18n, const char *msgid)
58 {
59  const char *res = msgid;
60  if (SPA_LIKELY(i18n != NULL))
61  spa_interface_call_res(&i18n->iface,
62  struct spa_i18n_methods, res,
63  text, 0, msgid);
64  return res;
65 }
66 
67 static inline const char *
68 spa_i18n_ntext(struct spa_i18n *i18n, const char *msgid,
69  const char *msgid_plural, unsigned long int n)
70 {
71  const char *res = n == 1 ? msgid : msgid_plural;
72  if (SPA_LIKELY(i18n != NULL))
74  struct spa_i18n_methods, res,
75  ntext, 0, msgid, msgid_plural, n);
76  return res;
77 }
78 
83 #ifdef __cplusplus
84 } /* extern "C" */
85 #endif
86 
87 #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_text(struct spa_i18n *i18n, const char *msgid)
Definition: spa/include/spa/support/i18n.h:65
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:76
#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:235
#define SPA_LIKELY(x)
Definition: defs.h:341
spa/utils/hook.h
Definition: spa/include/spa/support/i18n.h:36
uint32_t version
Definition: spa/include/spa/support/i18n.h:39
Definition: spa/include/spa/support/i18n.h:34
struct spa_interface iface
Definition: spa/include/spa/support/i18n.h:34
Definition: hook.h:138