Magento 2 Get Translated StringMagento 2 - How to translate strings to a specific locale?translating a string with html elements in itString translation missingtranslated inline does not workM1.9 Translation string with link in csvget translated string Magento 2Upgrade to Magento 2.2.6 to Magento 2.3.1 Init vector must be a string of 32 bytesAnyway to force save Magento 2 general configuration changes?How can I regenerate vendor/magento/module-directory/etc/config.xml?How to translate string on mobile menu?

What is a Romeo Word™?

How to interpret a promising preprint that was never published in peer-review?

How long were the Apollo astronauts allowed to breathe 100% oxygen at 1 atmosphere continuously?

How to prove that the covariant derivative obeys the product rule

How many opportunity attacks can you make per turn before becoming exhausted?

Pauli exclusion principle - black holes

In this iconic lunar orbit rendezvous photo of John Houbolt, why do arrows #5 and #6 point the "wrong" way?

Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation

Did Hitler say this quote about homeschooling?

How to extract interesting piece of output in bash

Which modern firearm should a time traveler bring to be easily reproducible for a historic civilization?

What makes MOVEQ quicker than a normal MOVE in 68000 assembly?

Operation Unzalgo

What's a German word for »Sandbagger«?

Will the internet speed decrease on second router if there are multiple devices connected to primary router?

Why is the Intel 8086 CPU called a 16-bit CPU?

Do Australia and New Zealand have a travel ban on Somalis (like Wikipedia says)?

Why isn't a binary file shown as 0s and 1s?

Who would use the word "manky"?

Wait or be waiting?

Should I have one hand on the throttle during engine ignition?

BritRail England Passes compared to return ticket for travel in England

Brute-force the switchboard

How to belay quickly ascending top-rope climbers?



Magento 2 Get Translated String


Magento 2 - How to translate strings to a specific locale?translating a string with html elements in itString translation missingtranslated inline does not workM1.9 Translation string with link in csvget translated string Magento 2Upgrade to Magento 2.2.6 to Magento 2.3.1 Init vector must be a string of 32 bytesAnyway to force save Magento 2 general configuration changes?How can I regenerate vendor/magento/module-directory/etc/config.xml?How to translate string on mobile menu?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Is there a way to get translated string in php code?



Something like this:



$string = __('something');
foreach ($stores as $store)
echo $store->getName().': '.$store->getTranslated($string)."n";


\-- output:
english: someting
italian: qualcosa
french: quelque chose


EDIT:
@Vinz suggestion could be a nice workaround but I need to use __() function or prashes won't be collected for dictionary.



in magento 1 I used;



$newLocaleCode = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeCode);
$initialEnvironmentInfo = Mage::getSingleton('core/app_emulation')->startEnvironmentEmulation($storeCode);
Mage::getSingleton('core/translate')->setLocale($newLocaleCode)->init(Mage_Core_Model_App_Area::AREA_FRONTEND, true);
Mage::getSingleton('core/app_emulation')->stopEnvironmentEmulation($initialEnvironmentInfo);


so after some research i found this:



 /**
* MagentoStoreModelAppEmulation
*/
protected $emulation;

public function __construct(MagentoStoreModelAppEmulation $emulation)
$this->emulation = $emulation;


/**
* example function in which we want to emulate a stores environment
*/
public function example($storeId, $area = 'frontend')

//starting the store emulation with area defined for admin
$this->emulation->startEnvironmentEmulation($storeId, 'adminhtml');

//you can update or save a product attributes here with correct scope or anything else you want to do, perform some test

// discard the emulated environment after doing your work
$this->emulation->stopEnvironmentEmulation();




at this link:
https://webkul.com/blog/magento2-store-emulation/



This works fine.










share|improve this question



















  • 4





    Possible duplicate of Magento 2 - How to translate strings to a specific locale?

    – Vinz
    Jul 10 at 17:31











  • this could be a workaround, but the __() function is missed and phrases won't be collected for dictionary.

    – krybbio
    Jul 10 at 17:35

















0















Is there a way to get translated string in php code?



Something like this:



$string = __('something');
foreach ($stores as $store)
echo $store->getName().': '.$store->getTranslated($string)."n";


\-- output:
english: someting
italian: qualcosa
french: quelque chose


EDIT:
@Vinz suggestion could be a nice workaround but I need to use __() function or prashes won't be collected for dictionary.



in magento 1 I used;



$newLocaleCode = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeCode);
$initialEnvironmentInfo = Mage::getSingleton('core/app_emulation')->startEnvironmentEmulation($storeCode);
Mage::getSingleton('core/translate')->setLocale($newLocaleCode)->init(Mage_Core_Model_App_Area::AREA_FRONTEND, true);
Mage::getSingleton('core/app_emulation')->stopEnvironmentEmulation($initialEnvironmentInfo);


so after some research i found this:



 /**
* MagentoStoreModelAppEmulation
*/
protected $emulation;

public function __construct(MagentoStoreModelAppEmulation $emulation)
$this->emulation = $emulation;


/**
* example function in which we want to emulate a stores environment
*/
public function example($storeId, $area = 'frontend')

//starting the store emulation with area defined for admin
$this->emulation->startEnvironmentEmulation($storeId, 'adminhtml');

//you can update or save a product attributes here with correct scope or anything else you want to do, perform some test

// discard the emulated environment after doing your work
$this->emulation->stopEnvironmentEmulation();




at this link:
https://webkul.com/blog/magento2-store-emulation/



This works fine.










share|improve this question



















  • 4





    Possible duplicate of Magento 2 - How to translate strings to a specific locale?

    – Vinz
    Jul 10 at 17:31











  • this could be a workaround, but the __() function is missed and phrases won't be collected for dictionary.

    – krybbio
    Jul 10 at 17:35













0












0








0








Is there a way to get translated string in php code?



Something like this:



$string = __('something');
foreach ($stores as $store)
echo $store->getName().': '.$store->getTranslated($string)."n";


\-- output:
english: someting
italian: qualcosa
french: quelque chose


EDIT:
@Vinz suggestion could be a nice workaround but I need to use __() function or prashes won't be collected for dictionary.



in magento 1 I used;



$newLocaleCode = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeCode);
$initialEnvironmentInfo = Mage::getSingleton('core/app_emulation')->startEnvironmentEmulation($storeCode);
Mage::getSingleton('core/translate')->setLocale($newLocaleCode)->init(Mage_Core_Model_App_Area::AREA_FRONTEND, true);
Mage::getSingleton('core/app_emulation')->stopEnvironmentEmulation($initialEnvironmentInfo);


so after some research i found this:



 /**
* MagentoStoreModelAppEmulation
*/
protected $emulation;

public function __construct(MagentoStoreModelAppEmulation $emulation)
$this->emulation = $emulation;


/**
* example function in which we want to emulate a stores environment
*/
public function example($storeId, $area = 'frontend')

//starting the store emulation with area defined for admin
$this->emulation->startEnvironmentEmulation($storeId, 'adminhtml');

//you can update or save a product attributes here with correct scope or anything else you want to do, perform some test

// discard the emulated environment after doing your work
$this->emulation->stopEnvironmentEmulation();




at this link:
https://webkul.com/blog/magento2-store-emulation/



This works fine.










share|improve this question
















Is there a way to get translated string in php code?



Something like this:



$string = __('something');
foreach ($stores as $store)
echo $store->getName().': '.$store->getTranslated($string)."n";


\-- output:
english: someting
italian: qualcosa
french: quelque chose


EDIT:
@Vinz suggestion could be a nice workaround but I need to use __() function or prashes won't be collected for dictionary.



in magento 1 I used;



$newLocaleCode = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeCode);
$initialEnvironmentInfo = Mage::getSingleton('core/app_emulation')->startEnvironmentEmulation($storeCode);
Mage::getSingleton('core/translate')->setLocale($newLocaleCode)->init(Mage_Core_Model_App_Area::AREA_FRONTEND, true);
Mage::getSingleton('core/app_emulation')->stopEnvironmentEmulation($initialEnvironmentInfo);


so after some research i found this:



 /**
* MagentoStoreModelAppEmulation
*/
protected $emulation;

public function __construct(MagentoStoreModelAppEmulation $emulation)
$this->emulation = $emulation;


/**
* example function in which we want to emulate a stores environment
*/
public function example($storeId, $area = 'frontend')

//starting the store emulation with area defined for admin
$this->emulation->startEnvironmentEmulation($storeId, 'adminhtml');

//you can update or save a product attributes here with correct scope or anything else you want to do, perform some test

// discard the emulated environment after doing your work
$this->emulation->stopEnvironmentEmulation();




at this link:
https://webkul.com/blog/magento2-store-emulation/



This works fine.







magento2.3.1 translate






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 10 at 19:08







krybbio

















asked Jul 10 at 14:51









krybbiokrybbio

6997 silver badges22 bronze badges




6997 silver badges22 bronze badges







  • 4





    Possible duplicate of Magento 2 - How to translate strings to a specific locale?

    – Vinz
    Jul 10 at 17:31











  • this could be a workaround, but the __() function is missed and phrases won't be collected for dictionary.

    – krybbio
    Jul 10 at 17:35












  • 4





    Possible duplicate of Magento 2 - How to translate strings to a specific locale?

    – Vinz
    Jul 10 at 17:31











  • this could be a workaround, but the __() function is missed and phrases won't be collected for dictionary.

    – krybbio
    Jul 10 at 17:35







4




4





Possible duplicate of Magento 2 - How to translate strings to a specific locale?

– Vinz
Jul 10 at 17:31





Possible duplicate of Magento 2 - How to translate strings to a specific locale?

– Vinz
Jul 10 at 17:31













this could be a workaround, but the __() function is missed and phrases won't be collected for dictionary.

– krybbio
Jul 10 at 17:35





this could be a workaround, but the __() function is missed and phrases won't be collected for dictionary.

– krybbio
Jul 10 at 17:35










0






active

oldest

votes














Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281594%2fmagento-2-get-translated-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281594%2fmagento-2-get-translated-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?