Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / parser / htmlparser / nsParserMsgUtils.cpp
blob627f57a0e854b14f6d5e6428a1a6ec027575ee44
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 "nsIServiceManager.h"
7 #include "nsIStringBundle.h"
8 #include "nsXPIDLString.h"
9 #include "nsParserMsgUtils.h"
10 #include "nsNetCID.h"
11 #include "mozilla/Services.h"
13 static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle)
15 NS_ENSURE_ARG_POINTER(aPropFileName);
16 NS_ENSURE_ARG_POINTER(aBundle);
18 // Create a bundle for the localization
20 nsCOMPtr<nsIStringBundleService> stringService =
21 mozilla::services::GetStringBundleService();
22 if (!stringService)
23 return NS_ERROR_FAILURE;
25 return stringService->CreateBundle(aPropFileName, aBundle);
28 nsresult
29 nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& oVal)
31 oVal.Truncate();
33 NS_ENSURE_ARG_POINTER(aKey);
35 nsCOMPtr<nsIStringBundle> bundle;
36 nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
37 if (NS_SUCCEEDED(rv) && bundle) {
38 nsXPIDLString valUni;
39 nsAutoString key; key.AssignWithConversion(aKey);
40 rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni));
41 if (NS_SUCCEEDED(rv) && valUni) {
42 oVal.Assign(valUni);
46 return rv;
49 nsresult
50 nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName, uint32_t aID, nsString& oVal)
52 oVal.Truncate();
54 nsCOMPtr<nsIStringBundle> bundle;
55 nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
56 if (NS_SUCCEEDED(rv) && bundle) {
57 nsXPIDLString valUni;
58 rv = bundle->GetStringFromID(aID, getter_Copies(valUni));
59 if (NS_SUCCEEDED(rv) && valUni) {
60 oVal.Assign(valUni);
64 return rv;