@@ -155,14 +155,20 @@ class SerializedLocalizationWriter {
155
155
156
156
class LocalizationProducer {
157
157
public:
158
- // / If the message isn't available/localized in the current `yaml` file,
158
+ // / If the message isn't available/localized in current context
159
159
// / return the fallback default message.
160
160
virtual llvm::StringRef getMessageOr (swift::DiagID id,
161
161
llvm::StringRef defaultMessage) const {
162
- return defaultMessage;
162
+ auto message = getMessage (id);
163
+ return message.empty () ? defaultMessage : message;
163
164
}
164
165
165
166
virtual ~LocalizationProducer () {}
167
+
168
+ protected:
169
+ // / Retrieve a message for the given diagnostic id.
170
+ // / \returns empty string if message couldn't be found.
171
+ virtual llvm::StringRef getMessage (swift::DiagID id) const = 0;
166
172
};
167
173
168
174
class YAMLLocalizationProducer final : public LocalizationProducer {
@@ -172,14 +178,15 @@ class YAMLLocalizationProducer final : public LocalizationProducer {
172
178
// / The diagnostics IDs that are no longer available in `.def`
173
179
std::vector<std::string> unknownIDs;
174
180
explicit YAMLLocalizationProducer (llvm::StringRef filePath);
175
- llvm::StringRef getMessageOr (swift::DiagID id,
176
- llvm::StringRef defaultMessage) const override ;
177
181
178
182
// / Iterate over all of the available (non-empty) translations
179
183
// / maintained by this producer, callback gets each translation
180
184
// / with its unique identifier.
181
185
void forEachAvailable (
182
186
llvm::function_ref<void (swift::DiagID, llvm::StringRef)> callback) const ;
187
+
188
+ protected:
189
+ llvm::StringRef getMessage (swift::DiagID id) const override ;
183
190
};
184
191
185
192
class SerializedLocalizationProducer final : public LocalizationProducer {
@@ -193,8 +200,8 @@ class SerializedLocalizationProducer final : public LocalizationProducer {
193
200
explicit SerializedLocalizationProducer (
194
201
std::unique_ptr<llvm::MemoryBuffer> buffer);
195
202
196
- llvm::StringRef getMessageOr (swift::DiagID id,
197
- llvm::StringRef defaultMessage ) const override ;
203
+ protected:
204
+ llvm::StringRef getMessage (swift::DiagID id ) const override ;
198
205
};
199
206
200
207
class LocalizationInput : public llvm ::yaml::Input {
0 commit comments