Backed out changeset bcbab342eed8 (bug 1889658) for causing wpt reftest failures...
[gecko.git] / parser / htmlparser / nsParserMsgUtils.cpp
bloba629bcc5e32be930a8bd9f48ae451fb449172b48
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsIStringBundle.h"
7 #include "nsString.h"
8 #include "nsParserMsgUtils.h"
9 #include "nsNetCID.h"
10 #include "mozilla/Components.h"
12 static nsresult GetBundle(const char* aPropFileName,
13 nsIStringBundle** aBundle) {
14 NS_ENSURE_ARG_POINTER(aPropFileName);
15 NS_ENSURE_ARG_POINTER(aBundle);
17 // Create a bundle for the localization
19 nsCOMPtr<nsIStringBundleService> stringService =
20 mozilla::components::StringBundle::Service();
21 if (!stringService) return NS_ERROR_FAILURE;
23 return stringService->CreateBundle(aPropFileName, aBundle);
26 nsresult nsParserMsgUtils::GetLocalizedStringByName(const char* aPropFileName,
27 const char* aKey,
28 nsString& oVal) {
29 oVal.Truncate();
31 NS_ENSURE_ARG_POINTER(aKey);
33 nsCOMPtr<nsIStringBundle> bundle;
34 nsresult rv = GetBundle(aPropFileName, getter_AddRefs(bundle));
35 if (NS_SUCCEEDED(rv) && bundle) {
36 nsAutoString valUni;
37 rv = bundle->GetStringFromName(aKey, valUni);
38 if (NS_SUCCEEDED(rv)) {
39 oVal.Assign(valUni);
43 return rv;
46 nsresult nsParserMsgUtils::GetLocalizedStringByID(const char* aPropFileName,
47 uint32_t aID,
48 nsString& oVal) {
49 oVal.Truncate();
51 nsCOMPtr<nsIStringBundle> bundle;
52 nsresult rv = GetBundle(aPropFileName, getter_AddRefs(bundle));
53 if (NS_SUCCEEDED(rv) && bundle) {
54 nsAutoString valUni;
55 rv = bundle->GetStringFromID(aID, valUni);
56 if (NS_SUCCEEDED(rv)) {
57 oVal.Assign(valUni);
61 return rv;