~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins/Mono.Addins/AddinLocalizer.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// AddinLocalizer.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
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:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
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.
 
27
//
 
28
 
 
29
using System;
 
30
using Mono.Addins.Localization;
 
31
 
 
32
namespace Mono.Addins
 
33
{
 
34
        /// <summary>
 
35
        /// Converts message identifiers to localized messages.
 
36
        /// </summary>
 
37
        public class AddinLocalizer
 
38
        {
 
39
                IAddinLocalizer localizer;
 
40
                IPluralAddinLocalizer pluralLocalizer;
 
41
                
 
42
                internal AddinLocalizer (IAddinLocalizer localizer)
 
43
                {
 
44
                        this.localizer = localizer;
 
45
                        pluralLocalizer = localizer as IPluralAddinLocalizer;
 
46
                }
 
47
 
 
48
                /// <summary>
 
49
                /// Gets a localized message
 
50
                /// </summary>
 
51
                /// <param name="msgid">
 
52
                /// Message identifier
 
53
                /// </param>
 
54
                /// <returns>
 
55
                /// The localized message
 
56
                /// </returns>
 
57
                public string GetString (string msgid)
 
58
                {
 
59
                        return localizer.GetString (msgid);
 
60
                }
 
61
                
 
62
                /// <summary>
 
63
                /// Gets a formatted and localized message
 
64
                /// </summary>
 
65
                /// <param name="msgid">
 
66
                /// Message identifier (can contain string format placeholders)
 
67
                /// </param>
 
68
                /// <param name="args">
 
69
                /// Arguments for the string format operation
 
70
                /// </param>
 
71
                /// <returns>
 
72
                /// The formatted and localized string
 
73
                /// </returns>
 
74
                public string GetString (string msgid, params string[] args)
 
75
                {
 
76
                        return string.Format (localizer.GetString (msgid), args);
 
77
                }
 
78
                
 
79
                /// <summary>
 
80
                /// Gets a formatted and localized message
 
81
                /// </summary>
 
82
                /// <param name="msgid">
 
83
                /// Message identifier (can contain string format placeholders)
 
84
                /// </param>
 
85
                /// <param name="args">
 
86
                /// Arguments for the string format operation
 
87
                /// </param>
 
88
                /// <returns>
 
89
                /// The formatted and localized string
 
90
                /// </returns>
 
91
                public string GetString (string msgid, params object[] args)
 
92
                {
 
93
                        return string.Format (localizer.GetString (msgid), args);
 
94
                }
 
95
 
 
96
                /// <summary>
 
97
                /// Gets a localized plural form for a message identifier
 
98
                /// </summary>
 
99
                /// <param name="msgid">
 
100
                /// Message identifier for the singular form
 
101
                /// </param>
 
102
                /// <param name="defaultPlural">
 
103
                /// Default result message for the plural form
 
104
                /// </param>
 
105
                /// <param name="n">
 
106
                /// Value count. Determines wether to use singular or plural form.
 
107
                /// </param>
 
108
                /// <returns>
 
109
                /// The localized message
 
110
                /// </returns>
 
111
                public string GetPluralString (string msgid, string defaultPlural, int n)
 
112
                {
 
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.
 
116
                        
 
117
                        if (pluralLocalizer != null)
 
118
                                return pluralLocalizer.GetPluralString (msgid, defaultPlural, n);
 
119
                        else
 
120
                                return GetString (msgid);
 
121
                }
 
122
                
 
123
                /// <summary>
 
124
                /// Gets a localized and formatted plural form for a message identifier
 
125
                /// </summary>
 
126
                /// <param name="singular">
 
127
                /// Message identifier for the singular form (can contain string format placeholders)
 
128
                /// </param>
 
129
                /// <param name="defaultPlural">
 
130
                /// Default result message for the plural form (can contain string format placeholders)
 
131
                /// </param>
 
132
                /// <param name="n">
 
133
                /// Value count. Determines whether to use singular or plural form.
 
134
                /// </param>
 
135
                /// <param name="args">
 
136
                /// Arguments for the string format operation
 
137
                /// </param>
 
138
                /// <returns>
 
139
                /// The localized message
 
140
                /// </returns>
 
141
                public string GetPluralString (string singular, string defaultPlural, int n, params string[] args)
 
142
                {
 
143
                        return string.Format (GetPluralString (singular, defaultPlural, n), args);
 
144
                }
 
145
                
 
146
                /// <summary>
 
147
                /// Gets a localized and formatted plural form for a message identifier
 
148
                /// </summary>
 
149
                /// <param name="singular">
 
150
                /// Message identifier for the singular form (can contain string format placeholders)
 
151
                /// </param>
 
152
                /// <param name="defaultPlural">
 
153
                /// Default result message for the plural form (can contain string format placeholders)
 
154
                /// </param>
 
155
                /// <param name="n">
 
156
                /// Value count. Determines whether to use singular or plural form.
 
157
                /// </param>
 
158
                /// <param name="args">
 
159
                /// Arguments for the string format operation
 
160
                /// </param>
 
161
                /// <returns>
 
162
                /// The localized message
 
163
                /// </returns>
 
164
                public string GetPluralString (string singular, string defaultPlural, int n, params object[] args)
 
165
                {
 
166
                        return string.Format (GetPluralString (singular, defaultPlural, n), args);
 
167
                }
 
168
        }
 
169
}