Check-in [016afc2026]

Login
Bounty program for improvements to Tcl and certain Tcl packages.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:tip490 oo for msgcat: re-changed "option" to "extension"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 016afc2026cb29ea05499244dcbf1097474db3d4d3ae40a5dc56b98d7a020ca3
User & Date: oehhar 2018-03-09 10:05:54
Context
2018-03-10
13:45
Allow filtering of more TIP states (inadvertently forgotten previously) check-in: 87d94d7d82 user: dkf tags: trunk
2018-03-09
10:05
tip490 oo for msgcat: re-changed "option" to "extension" check-in: 016afc2026 user: oehhar tags: trunk
2018-03-08
14:24
More formatting tweaking check-in: 072c7a281d user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tip/490.md.

125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

266
267
268

269

270
271
272
273
274
275
276
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
-> Servus!
</pre>

This should still work with the new extension for compatibility reasons.

# Proposal

There are 4 possible proposed ways of extending msgcat to support
this. _We intend to implement the first option._


## Option 1: Extend all msgcat commands to support all 4 use-cases.

So any **msgcat** command will detect the scenario on its own and extract the package namespace automatically.

The commands which are packet-namespace related are: **mc**, **mcexists**, **mcpackagelocale**, **mcforgetpackage**, **mcpackagenamespaceget** (new command, see below), **mcpackageconfig**, **mcset** and **mcmset**.

This has the following advantages (compared to the alternatives):

................................................................................
    ...
    set message [uplevel 1 {::msgcat::mc $message}]
}
</pre>

This will work in all use-cases, e.g. if `tooltip::tooltip` is called by a method following use-case 1 to 4.

## Option 2: new command to get package namespace

The "magic" to extract the package namespace is exposed by the command:

<pre>
mcpackagenamespaceget
</pre>

................................................................................
proc ::tooltip::show {widget messagenamespace message} {
    ...
    set message [namespace eval $messagenamespace [list ::msgcat::mc $message]]
    ...
}
</pre>

Examples with the 4 use-cases:

1. First use case: the package does not use OO

	<pre>
	namespace eval ::N1 {
	    proc m1 {} {msgcat::mcpackagenamespaceget}
	}

	% N1::m1
	-> ::N1
	</pre>

2. Second use case: call within class definition script

	<pre>
	% namespace eval ::N2Class {
	    oo::class create C1 {puts "pns=[msgcat::mcpackagenamespaceget]"}
	}
	-> pns=::N2Class
	-> ::N2Class::C1
	</pre>

3. Third use case: The package implementation is done by a class

	<pre>
	namespace eval ::N3Class {
	    oo::class create C1
	    oo::define C1 method m1 {msgcat::mcpackagenamespaceget}
	}

	# The class object may be used in another namespace

	namespace eval ::N3Obj {
	    set O1 [::N3Class::C1 new]
	}

	% $N3Obj::O1 m1
	-> ::N3Class
	</pre>

4. Fourth use case: The package implementation is done by a classless object

	<pre>
	namespace eval ::N4 {
	    oo::object create O1
	    oo::objdefine O1 method m1 {} {msgcat::mcpackagenamespaceget}
	}

	% N4::O1 m1
	-> ::N4
	</pre>

### Manually overwriting the package namespace by namespace eval

As stated in the introduction, current OO code might have used an explicit `namespace eval packagenamespace` to make msgcat work. This should still be supported:

<pre>
namespace eval ::N4 {
    oo::object create O1
    oo::objdefine O1 method m1 {} {
        namespace eval ::N5 { msgcat::mcpackagenamespaceget}
    }
}

% N4::O1 m1
-> ::N5
</pre>

Note that in most real cases, one will explicitly specify "`::N4`" instead "`::N5`", as this is the package namespace.
"`::N5`" was chosen in the example to show the fact, that the `namespace eval` overrides any class-magic.

## Option 3: new command to get a translation with a package namespace as argument

A new command is proposed to get a translation with an explicit namespace:

<pre>
mcn ns src args...
</pre>

with the arguments:

* ns: package namespace to do the translation for
* src: the translation source string (like mc command)
* args: eventual arguments to contained format patterns (like mc command)

This command is identical to the `mc` command, with the difference, that the package namespace is not found by an implicit call to `mcpackagenamespaceget`, but may be explicitly specified as first argument

Then, the `mc` command may be expressed like:
................................................................................
proc ::tooltip::show {widget messagenamespace message} {
    ...
    set message [::msgcat::mcn $messagenamespace $message]
}
</pre>


## Option 4: Command "mcexists" should get a parameter -namespace to explicitly specify the namespace

The command `mcexists` has currently the syntax:

<pre>
mcexists ?-exactnamespace? ?-exactlocale? src
</pre>







|
<

>
|







 







|







 







<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|


>



>

>







 







|







125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
184
185
186
187
188
189
190

191






































































192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
-> Servus!
</pre>

This should still work with the new extension for compatibility reasons.

# Proposal

The following 4 extensions are proposed and covered by the TIP.



## Extension 1: Extend all msgcat commands to support all 4 use-cases.

So any **msgcat** command will detect the scenario on its own and extract the package namespace automatically.

The commands which are packet-namespace related are: **mc**, **mcexists**, **mcpackagelocale**, **mcforgetpackage**, **mcpackagenamespaceget** (new command, see below), **mcpackageconfig**, **mcset** and **mcmset**.

This has the following advantages (compared to the alternatives):

................................................................................
    ...
    set message [uplevel 1 {::msgcat::mc $message}]
}
</pre>

This will work in all use-cases, e.g. if `tooltip::tooltip` is called by a method following use-case 1 to 4.

## Extension 2: new command to get package namespace

The "magic" to extract the package namespace is exposed by the command:

<pre>
mcpackagenamespaceget
</pre>

................................................................................
proc ::tooltip::show {widget messagenamespace message} {
    ...
    set message [namespace eval $messagenamespace [list ::msgcat::mc $message]]
    ...
}
</pre>









































































## Extension 3: new command to get a translation with a package namespace as argument

A new command is proposed to get a translation with an explicit namespace:

<pre>
mcn ns src args...
</pre>

with the arguments:

* ns: package namespace to do the translation for
* src: the translation source string (like mc command)
* args: eventual arguments to contained format patterns (like mc command)

This command is identical to the `mc` command, with the difference, that the package namespace is not found by an implicit call to `mcpackagenamespaceget`, but may be explicitly specified as first argument

Then, the `mc` command may be expressed like:
................................................................................
proc ::tooltip::show {widget messagenamespace message} {
    ...
    set message [::msgcat::mcn $messagenamespace $message]
}
</pre>


## Extension 4: Command "mcexists" should get a parameter -namespace to explicitly specify the namespace

The command `mcexists` has currently the syntax:

<pre>
mcexists ?-exactnamespace? ?-exactlocale? src
</pre>