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

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form