@@ -4,6 +4,12 @@ import type { Extension } from './extension.js';
4
4
import type Gio from '@girs/gio-2.0' ;
5
5
import type GObject from '@girs/gobject-2.0' ;
6
6
7
+ /**
8
+ * @see https://gjs.guide/extensions/development/translations.html#marking-strings-for-translation
9
+ * @notes in Gnome Shell every string has format, since String.prototype.format() is added by it, but the best practices state, that only gettext functions use that, we already have that types in "global.d.ts" but if you don't want to have that type on every string, it is the return type of all those functions without importing the global types
10
+ */
11
+ export type FormattableString = string & { format : ( ...args : any [ ] ) => string } ;
12
+
7
13
export interface TranslationFunctions {
8
14
/**
9
15
* Translate `str` using the extension's gettext domain
@@ -12,7 +18,7 @@ export interface TranslationFunctions {
12
18
*
13
19
* @returns {string } the translated string
14
20
*/
15
- gettext ( str : string ) : string
21
+ gettext ( str : string ) : FormattableString ;
16
22
/**
17
23
* Translate `str` and choose plural form using the extension's
18
24
* gettext domain
@@ -23,7 +29,7 @@ export interface TranslationFunctions {
23
29
*
24
30
* @returns {string } the translated string
25
31
*/
26
- ngettext ( str : string , strPlural : string , n : number ) : string
32
+ ngettext ( str : string , strPlural : string , n : number ) : FormattableString ;
27
33
28
34
/**
29
35
* Translate `str` in the context of `context` using the extension's
@@ -34,38 +40,38 @@ export interface TranslationFunctions {
34
40
*
35
41
* @returns {string } the translated string
36
42
*/
37
- pgettext ( context : string , str : string ) : string
43
+ pgettext ( context : string , str : string ) : FormattableString ;
38
44
}
39
45
40
46
export class ExtensionBase {
41
47
#gettextDomain: string | null ;
42
48
43
- readonly metadata : ExtensionMetadata
49
+ readonly metadata : ExtensionMetadata ;
44
50
45
51
/**
46
52
* Look up an extension by URL (usually 'import.meta.url')
47
53
*
48
54
* @param url - a file:// URL
49
55
*/
50
- static lookupByURL ( url : string ) : Extension | null
56
+ static lookupByURL ( url : string ) : Extension | null ;
51
57
52
58
/**
53
59
* Look up an extension by UUID
54
60
*
55
61
* @param {string } _uuid
56
62
*/
57
- static lookupByUUID ( _uuid : string ) : Extension | null
63
+ static lookupByUUID ( _uuid : string ) : Extension | null ;
58
64
59
65
/**
60
66
* @param metadata - metadata passed in when loading the extension
61
67
*/
62
- constructor ( metadata : ExtensionMetadata )
68
+ constructor ( metadata : ExtensionMetadata ) ;
63
69
64
- get uuid ( ) : string
70
+ get uuid ( ) : string ;
65
71
66
- get dir ( ) : Gio . File
72
+ get dir ( ) : Gio . File ;
67
73
68
- get path ( ) : string
74
+ get path ( ) : string ;
69
75
70
76
/**
71
77
* Get a GSettings object for schema, using schema files in
@@ -76,7 +82,7 @@ export class ExtensionBase {
76
82
*
77
83
* @returns { }
78
84
*/
79
- getSettings ( schema ?: string ) : Gio . Settings
85
+ getSettings ( schema ?: string ) : Gio . Settings ;
80
86
81
87
/**
82
88
* Initialize Gettext to load translations from extensionsdir/locale. If
@@ -85,7 +91,7 @@ export class ExtensionBase {
85
91
*
86
92
* @param {string= } domain - the gettext domain to use
87
93
*/
88
- initTranslations ( domain : string ) : void
94
+ initTranslations ( domain : string ) : void ;
89
95
90
96
/**
91
97
* Translate `str` using the extension's gettext domain
@@ -94,7 +100,7 @@ export class ExtensionBase {
94
100
*
95
101
* @returns the translated string
96
102
*/
97
- gettext ( str : string ) : string
103
+ gettext ( str : string ) : FormattableString ;
98
104
99
105
/**
100
106
* Translate `str` and choose plural form using the extension's
@@ -106,7 +112,7 @@ export class ExtensionBase {
106
112
*
107
113
* @returns {string } the translated string
108
114
*/
109
- ngettext ( str : string , strPlural : string , n : number ) : string
115
+ ngettext ( str : string , strPlural : string , n : number ) : FormattableString ;
110
116
111
117
/**
112
118
* Translate `str` in the context of `context` using the extension's
@@ -117,29 +123,29 @@ export class ExtensionBase {
117
123
*
118
124
* @returns {string } the translated string
119
125
*/
120
- pgettext ( context : string , str : string ) : string
126
+ pgettext ( context : string , str : string ) : FormattableString ;
121
127
122
128
/**
123
129
* @param {string } func
124
130
*/
125
- #checkGettextDomain( func : string )
131
+ #checkGettextDomain( func : string ) ;
126
132
}
127
133
128
134
export class GettextWrapper {
129
135
#url: string | null ;
130
136
#extensionClass: ExtensionBase ;
131
137
132
- constructor ( extensionClass : ExtensionBase , url : string )
138
+ constructor ( extensionClass : ExtensionBase , url : string ) ;
133
139
134
- #detectUrl( ) : string | null
140
+ #detectUrl( ) : string | null ;
135
141
136
- #lookupExtension( funcName : string ) : ExtensionBase
142
+ #lookupExtension( funcName : string ) : ExtensionBase ;
137
143
138
- #gettext( str : string ) : string
144
+ #gettext( str : string ) : FormattableString ;
139
145
140
- #ngettext( str : string , strPlural : string , n : number ) : string
146
+ #ngettext( str : string , strPlural : string , n : number ) : FormattableString ;
141
147
142
- #pgettext( context :any , str : string ) : string
148
+ #pgettext( context : any , str : string ) : FormattableString ;
143
149
144
- defineTranslationFunctions ( ) : TranslationFunctions
150
+ defineTranslationFunctions ( ) : TranslationFunctions ;
145
151
}
0 commit comments