I'm trying to set labels for attributes for each language. For example I want to translate Price (in Stores > Attributes > Product > Price > Manage labels) for all the store views. enter image description here

However, I can't seem to find a way to do this via UpgradeData.php. I don't want to directly inject with an SQL query. Looking for something like this, but it doesn't work:

if (version_compare($context->getVersion(), '0.0.xx') < 0) {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $attributeId = $eavSetup->getAttributeId('catalog_product', 'price');
        $options = [
            'values' => [
                'Dutch(NL)' => 'Prijs',
            'attribute_id' => $attributeId,

1 Answer 1


You can set the frontend labels with the following code in your UpgradeData or InstallData script:

    /** @var \Magento\Eav\Setup\EavSetup $eavSetup */
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    $attribute = $this->productAttributeRepository->get($attributeCode);
    $sourceModel = $attribute->getSourceModel();
    $frontendLabels = [
            ->setLabel('Label 1'),
            ->setLabel('Label 2'),

    if ($sourceModel !== null) {
        ); // this is needed as the attribute repository throws away the source model while saving in Magento 2.2.5

$this->eavSetupFactory is of type \Magento\Eav\Setup\EavSetupFactory.

$this->productAttributeRepository is of type \Magento\Catalog\Api\ProductAttributeRepositoryInterface.

$this->attributeFrontendLabelFactory is of type \Magento\Eav\Api\Data\AttributeFrontendLabelInterfaceFactory.

You should inject them via Dependency Injection in the constructor.

  • Thank you! I've been also trying to keep the already set labels by getting labels by getFrontendLabels() and appending my store label, and since this function return type is clearly an array * @return \Magento\Eav\Api\Data\AttributeFrontendLabelInterface[] I expected an array merge would suffice but kept getting this warning that "array_merge(): Argument #1 is not an array", I'm gonna see it through ...
    – medmek
    Commented Sep 9, 2018 at 20:06
  • $eavSetup->updateAttribute(...) not needed anymore, at least from Magento 2.3.5 or higher. Commented Nov 3, 2022 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.