mailnews/import/src/nsImportStringBundle.cpp
author Mozilla Releng Treescript <release+treescript@mozilla.org>
Fri, 16 Apr 2021 08:37:55 +0000
changeset 41725 cb3770be45480f9c20ca919ca25e30bdf9786f21
parent 39007 1aa86015cd87b30709412551835bf902025cd7d1
permissions -rw-r--r--
no bug - Bumping Thunderbird l10n changesets r=release a=l10n-bump DONTBUILD ast -> 051a43b56a8f71a6be38d40840e890ad6450c151 en-CA -> e25f759ad909899229070ef63723afeee1a41264 en-GB -> 23ae176e079088fa22dd49338781eb815e8cf4b6 es-AR -> a52ab0592c537a4184fff6fc4de4f2f6db96d17a fi -> a9f0f3ba1ae388ba7de523db82c698fdbde414d4 fr -> 8598ce8c657a2a16db72173d36c9f070be716af6 he -> becd3e30cb667f854fdf0d63feef61bf2fd26a2f hr -> f1f33174f2e4d0df9c4027836dc4c76c1bfac62e it -> 2bb3b62e853ad464384675ac3a25895425d29bad ko -> 19850b6910574097682094758899c8733c19a8ad nb-NO -> fefd0ab28ab896b4270a2a5c9e3b4f608fcd36af nl -> cb6ba46d59c2da8c1490de908c16002e35a46386 rm -> ea3bc056603e4bf3fb99721ba59faf8f30a36dc3 ru -> 4d78634ab8ac402a45322e26504c8e1d1337896a sq -> af39bd862702176c562d66859c8e1e4edd9d80a2 sv-SE -> a2130a7a49cc93a004ca9d191c4755ec24c8ea3e tr -> 4c27df9a1f0aa5c31906acfc377f08442f1783bb zh-CN -> 058380b002ca80e969587b7f9ce1bfaeae325d8e zh-TW -> 7e928c3d3632e7c52dc2c9ab0e5fb493ab132665

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "prprf.h"
#include "prmem.h"
#include "nsCOMPtr.h"
#include "nsIStringBundle.h"
#include "nsImportStringBundle.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "mozilla/Services.h"

nsresult nsImportStringBundle::GetStringBundle(const char* aPropertyURL,
                                               nsIStringBundle** aBundle) {
  nsresult rv;

  nsCOMPtr<nsIStringBundleService> sBundleService =
      mozilla::services::GetStringBundleService();
  NS_ENSURE_TRUE(sBundleService, NS_ERROR_UNEXPECTED);
  rv = sBundleService->CreateBundle(aPropertyURL, aBundle);

  return rv;
}

void nsImportStringBundle::GetStringByID(int32_t aStringID,
                                         nsIStringBundle* aBundle,
                                         nsString& aResult) {
  aResult.Adopt(GetStringByID(aStringID, aBundle));
}

char16_t* nsImportStringBundle::GetStringByID(int32_t aStringID,
                                              nsIStringBundle* aBundle) {
  if (aBundle) {
    nsAutoString str;
    nsresult rv = aBundle->GetStringFromID(aStringID, str);
    if (NS_SUCCEEDED(rv)) return ToNewUnicode(str);
  }

  nsString resultString(u"[StringID "_ns);
  resultString.AppendInt(aStringID);
  resultString.AppendLiteral("?]");

  return ToNewUnicode(resultString);
}

void nsImportStringBundle::GetStringByName(const char* aName,
                                           nsIStringBundle* aBundle,
                                           nsString& aResult) {
  aResult.Adopt(GetStringByName(aName, aBundle));
}

char16_t* nsImportStringBundle::GetStringByName(const char* aName,
                                                nsIStringBundle* aBundle) {
  if (aBundle) {
    nsAutoString str;
    nsresult rv = aBundle->GetStringFromName(aName, str);
    if (NS_SUCCEEDED(rv)) return ToNewUnicode(str);
  }

  nsString resultString(u"[StringName "_ns);
  resultString.Append(NS_ConvertUTF8toUTF16(aName).get());
  resultString.AppendLiteral("?]");

  return ToNewUnicode(resultString);
}