Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsIServiceManager.h" |
michael@0 | 7 | #include "nsIStringBundle.h" |
michael@0 | 8 | #include "nsXPIDLString.h" |
michael@0 | 9 | #include "nsParserMsgUtils.h" |
michael@0 | 10 | #include "nsNetCID.h" |
michael@0 | 11 | #include "mozilla/Services.h" |
michael@0 | 12 | |
michael@0 | 13 | static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle) |
michael@0 | 14 | { |
michael@0 | 15 | NS_ENSURE_ARG_POINTER(aPropFileName); |
michael@0 | 16 | NS_ENSURE_ARG_POINTER(aBundle); |
michael@0 | 17 | |
michael@0 | 18 | // Create a bundle for the localization |
michael@0 | 19 | |
michael@0 | 20 | nsCOMPtr<nsIStringBundleService> stringService = |
michael@0 | 21 | mozilla::services::GetStringBundleService(); |
michael@0 | 22 | if (!stringService) |
michael@0 | 23 | return NS_ERROR_FAILURE; |
michael@0 | 24 | |
michael@0 | 25 | return stringService->CreateBundle(aPropFileName, aBundle); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | nsresult |
michael@0 | 29 | nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& oVal) |
michael@0 | 30 | { |
michael@0 | 31 | oVal.Truncate(); |
michael@0 | 32 | |
michael@0 | 33 | NS_ENSURE_ARG_POINTER(aKey); |
michael@0 | 34 | |
michael@0 | 35 | nsCOMPtr<nsIStringBundle> bundle; |
michael@0 | 36 | nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle)); |
michael@0 | 37 | if (NS_SUCCEEDED(rv) && bundle) { |
michael@0 | 38 | nsXPIDLString valUni; |
michael@0 | 39 | nsAutoString key; key.AssignWithConversion(aKey); |
michael@0 | 40 | rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni)); |
michael@0 | 41 | if (NS_SUCCEEDED(rv) && valUni) { |
michael@0 | 42 | oVal.Assign(valUni); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | return rv; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | nsresult |
michael@0 | 50 | nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName, uint32_t aID, nsString& oVal) |
michael@0 | 51 | { |
michael@0 | 52 | oVal.Truncate(); |
michael@0 | 53 | |
michael@0 | 54 | nsCOMPtr<nsIStringBundle> bundle; |
michael@0 | 55 | nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle)); |
michael@0 | 56 | if (NS_SUCCEEDED(rv) && bundle) { |
michael@0 | 57 | nsXPIDLString valUni; |
michael@0 | 58 | rv = bundle->GetStringFromID(aID, getter_Copies(valUni)); |
michael@0 | 59 | if (NS_SUCCEEDED(rv) && valUni) { |
michael@0 | 60 | oVal.Assign(valUni); |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | return rv; |
michael@0 | 65 | } |