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"
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();
23 return NS_ERROR_FAILURE
;
25 return stringService
->CreateBundle(aPropFileName
, aBundle
);
29 nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName
, const char* aKey
, nsString
& oVal
)
33 NS_ENSURE_ARG_POINTER(aKey
);
35 nsCOMPtr
<nsIStringBundle
> bundle
;
36 nsresult rv
= GetBundle(aPropFileName
,getter_AddRefs(bundle
));
37 if (NS_SUCCEEDED(rv
) && bundle
) {
39 nsAutoString key
; key
.AssignWithConversion(aKey
);
40 rv
= bundle
->GetStringFromName(key
.get(), getter_Copies(valUni
));
41 if (NS_SUCCEEDED(rv
) && valUni
) {
50 nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName
, uint32_t aID
, nsString
& oVal
)
54 nsCOMPtr
<nsIStringBundle
> bundle
;
55 nsresult rv
= GetBundle(aPropFileName
,getter_AddRefs(bundle
));
56 if (NS_SUCCEEDED(rv
) && bundle
) {
58 rv
= bundle
->GetStringFromID(aID
, getter_Copies(valUni
));
59 if (NS_SUCCEEDED(rv
) && valUni
) {