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"
8 #include "nsParserMsgUtils.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
,
31 NS_ENSURE_ARG_POINTER(aKey
);
33 nsCOMPtr
<nsIStringBundle
> bundle
;
34 nsresult rv
= GetBundle(aPropFileName
, getter_AddRefs(bundle
));
35 if (NS_SUCCEEDED(rv
) && bundle
) {
37 rv
= bundle
->GetStringFromName(aKey
, valUni
);
38 if (NS_SUCCEEDED(rv
)) {
46 nsresult
nsParserMsgUtils::GetLocalizedStringByID(const char* aPropFileName
,
51 nsCOMPtr
<nsIStringBundle
> bundle
;
52 nsresult rv
= GetBundle(aPropFileName
, getter_AddRefs(bundle
));
53 if (NS_SUCCEEDED(rv
) && bundle
) {
55 rv
= bundle
->GetStringFromID(aID
, valUni
);
56 if (NS_SUCCEEDED(rv
)) {