7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using Mono.Addins.Localization;
35
/// Converts message identifiers to localized messages.
37
public class AddinLocalizer
39
IAddinLocalizer localizer;
40
IPluralAddinLocalizer pluralLocalizer;
42
internal AddinLocalizer (IAddinLocalizer localizer)
44
this.localizer = localizer;
45
pluralLocalizer = localizer as IPluralAddinLocalizer;
49
/// Gets a localized message
51
/// <param name="msgid">
52
/// Message identifier
55
/// The localized message
57
public string GetString (string msgid)
59
return localizer.GetString (msgid);
63
/// Gets a formatted and localized message
65
/// <param name="msgid">
66
/// Message identifier (can contain string format placeholders)
68
/// <param name="args">
69
/// Arguments for the string format operation
72
/// The formatted and localized string
74
public string GetString (string msgid, params string[] args)
76
return string.Format (localizer.GetString (msgid), args);
80
/// Gets a formatted and localized message
82
/// <param name="msgid">
83
/// Message identifier (can contain string format placeholders)
85
/// <param name="args">
86
/// Arguments for the string format operation
89
/// The formatted and localized string
91
public string GetString (string msgid, params object[] args)
93
return string.Format (localizer.GetString (msgid), args);
97
/// Gets a localized plural form for a message identifier
99
/// <param name="msgid">
100
/// Message identifier for the singular form
102
/// <param name="defaultPlural">
103
/// Default result message for the plural form
106
/// Value count. Determines wether to use singular or plural form.
109
/// The localized message
111
public string GetPluralString (string msgid, string defaultPlural, int n)
113
// If the localizer does not support plural forms, just use GetString to
114
// get a translation. It is not correct to check 'n' in this case because
115
// there is no guarantee that 'defaultPlural' will be translated.
117
if (pluralLocalizer != null)
118
return pluralLocalizer.GetPluralString (msgid, defaultPlural, n);
120
return GetString (msgid);
124
/// Gets a localized and formatted plural form for a message identifier
126
/// <param name="singular">
127
/// Message identifier for the singular form (can contain string format placeholders)
129
/// <param name="defaultPlural">
130
/// Default result message for the plural form (can contain string format placeholders)
133
/// Value count. Determines whether to use singular or plural form.
135
/// <param name="args">
136
/// Arguments for the string format operation
139
/// The localized message
141
public string GetPluralString (string singular, string defaultPlural, int n, params string[] args)
143
return string.Format (GetPluralString (singular, defaultPlural, n), args);
147
/// Gets a localized and formatted plural form for a message identifier
149
/// <param name="singular">
150
/// Message identifier for the singular form (can contain string format placeholders)
152
/// <param name="defaultPlural">
153
/// Default result message for the plural form (can contain string format placeholders)
156
/// Value count. Determines whether to use singular or plural form.
158
/// <param name="args">
159
/// Arguments for the string format operation
162
/// The localized message
164
public string GetPluralString (string singular, string defaultPlural, int n, params object[] args)
166
return string.Format (GetPluralString (singular, defaultPlural, n), args);