magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

php bin/magento i18n:pack creates unwanted dir #6260

Closed thomvanderboon closed 8 years ago

thomvanderboon commented 8 years ago

If you run the php bin/magento i18n:pack to install a language pack a /i18n directory is created at system root. If you have no permission to write at system root you wil get a mkdir error

Tested on 2.1.0 and 2.2.0-dev (both same result)

Steps to reproduce

  1. From website root
  2. cd ./var
  3. wget http://107.170.242.99/var/2.1.0/source_nl_NL.csv
  4. cd ..
  5. php bin/magento i18n:pack --mode=replace -d var/source_nl_NL.csv nl_NL

    Expected result

  6. Do not create i18n dir at / (system root)

    Actual result

  7. Creates /i18n at system root
  8. Creates language file in /i18n at system root
biojppm commented 8 years ago

I get this too. This makes it impossible to install any language pack.

I traced this further and it seems that some but not all modules are unregistered. This causes their paths to be empty and thus when the /i18n dir is appended to their paths the result is a dir at the root level.

I found this by adding a print to setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php at the method _buildPackFilesData():

$path = $this->_context->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
echo 'context='.$context."............path=".$path."\n";

... and this was the result (sorted, duplicates removed via piping sort -u):

context=frontend/Magento/blank............path=/home/user/magento/vendor/magento/theme-frontend-blank/i18n/
context=frontend/Magento/luma............path=/home/user/magento/vendor/magento/theme-frontend-luma/i18n/
context=Magento_AdminGws............path=/i18n/
context=Magento_AdminNotification............path=/home/user/magento/vendor/magento/module-admin-notification/i18n/
context=Magento_AdvancedCheckout............path=/i18n/
context=Magento_AdvancedPricingImportExport............path=/home/user/magento/vendor/magento/module-advanced-pricing-import-export/i18n/
context=Magento_AdvancedRule............path=/i18n/
context=Magento_AdvancedSalesRule............path=/i18n/
context=Magento_AdvancedSearch............path=/i18n/
context=Magento_Amqp............path=/i18n/
context=Magento_Authorization............path=/home/user/magento/vendor/magento/module-authorization/i18n/
context=Magento_Authorizenet............path=/home/user/magento/vendor/magento/module-authorizenet/i18n/
context=Magento_Backend............path=/home/user/magento/vendor/magento/module-backend/i18n/
context=Magento_Backup............path=/home/user/magento/vendor/magento/module-backup/i18n/
context=Magento_Banner............path=/i18n/
context=Magento_Braintree............path=/home/user/magento/vendor/magento/module-braintree/i18n/
context=Magento_Bundle............path=/home/user/magento/vendor/magento/module-bundle/i18n/
context=Magento_BundleStaging............path=/i18n/
context=Magento_Captcha............path=/home/user/magento/vendor/magento/module-captcha/i18n/
context=Magento_CatalogEvent............path=/i18n/
context=Magento_CatalogImportExport............path=/home/user/magento/vendor/magento/module-catalog-import-export/i18n/
context=Magento_CatalogInventory............path=/home/user/magento/vendor/magento/module-catalog-inventory/i18n/
context=Magento_Catalog............path=/home/user/magento/vendor/magento/module-catalog/i18n/
context=Magento_CatalogPermissions............path=/i18n/
context=Magento_CatalogRule............path=/home/user/magento/vendor/magento/module-catalog-rule/i18n/
context=Magento_CatalogRuleStaging............path=/i18n/
context=Magento_CatalogSearch............path=/home/user/magento/vendor/magento/module-catalog-search/i18n/
context=Magento_CatalogStaging............path=/i18n/
context=Magento_CatalogUrlRewrite............path=/home/user/magento/vendor/magento/module-catalog-url-rewrite/i18n/
context=Magento_CatalogUrlRewriteStaging............path=/i18n/
context=Magento_CatalogWidget............path=/home/user/magento/vendor/magento/module-catalog-widget/i18n/
context=Magento_CheckoutAgreements............path=/home/user/magento/vendor/magento/module-checkout-agreements/i18n/
context=Magento_Checkout............path=/home/user/magento/vendor/magento/module-checkout/i18n/
context=Magento_CheckoutStaging............path=/i18n/
context=Magento_Cms............path=/home/user/magento/vendor/magento/module-cms/i18n/
context=Magento_CmsStaging............path=/i18n/
context=Magento_Config............path=/home/user/magento/vendor/magento/module-config/i18n/
context=Magento_ConfigurableProduct............path=/home/user/magento/vendor/magento/module-configurable-product/i18n/
context=Magento_ConfigurableProductStaging............path=/i18n/
context=Magento_Contact............path=/home/user/magento/vendor/magento/module-contact/i18n/
context=Magento_Cookie............path=/home/user/magento/vendor/magento/module-cookie/i18n/
context=Magento_Cron............path=/home/user/magento/vendor/magento/module-cron/i18n/
context=Magento_CurrencySymbol............path=/home/user/magento/vendor/magento/module-currency-symbol/i18n/
context=Magento_CustomAttributeManagement............path=/i18n/
context=Magento_CustomerBalance............path=/i18n/
context=Magento_CustomerCustomAttributes............path=/i18n/
context=Magento_CustomerFinance............path=/i18n/
context=Magento_CustomerImportExport............path=/home/user/magento/vendor/magento/module-customer-import-export/i18n/
context=Magento_Customer............path=/home/user/magento/vendor/magento/module-customer/i18n/
context=Magento_CustomerSegment............path=/i18n/
context=Magento_Cybersource............path=/i18n/
context=Magento_Deploy............path=/home/user/magento/vendor/magento/module-deploy/i18n/
context=Magento_Developer............path=/home/user/magento/vendor/magento/module-developer/i18n/
context=Magento_Dhl............path=/home/user/magento/vendor/magento/module-dhl/i18n/
context=Magento_Directory............path=/home/user/magento/vendor/magento/module-directory/i18n/
context=Magento_Doc............path=/i18n/
context=Magento_DownloadableImportExport............path=/home/user/magento/vendor/magento/module-downloadable-import-export/i18n/
context=Magento_Downloadable............path=/home/user/magento/vendor/magento/module-downloadable/i18n/
context=Magento_Eav............path=/home/user/magento/vendor/magento/module-eav/i18n/
context=Magento_Elasticsearch............path=/i18n/
context=Magento_Email............path=/home/user/magento/vendor/magento/module-email/i18n/
context=Magento_EncryptionKey............path=/home/user/magento/vendor/magento/module-encryption-key/i18n/
context=Magento_Enterprise............path=/i18n/
context=Magento_Eway............path=/i18n/
context=Magento_Fedex............path=/home/user/magento/vendor/magento/module-fedex/i18n/
context=Magento_GiftCardAccount............path=/i18n/
context=Magento_GiftCard............path=/i18n/
context=Magento_GiftMessage............path=/home/user/magento/vendor/magento/module-gift-message/i18n/
context=Magento_GiftRegistry............path=/i18n/
context=Magento_GiftWrapping............path=/i18n/
context=Magento_GoogleAdwords............path=/home/user/magento/vendor/magento/module-google-adwords/i18n/
context=Magento_GoogleAnalytics............path=/home/user/magento/vendor/magento/module-google-analytics/i18n/
context=Magento_GoogleOptimizer............path=/home/user/magento/vendor/magento/module-google-optimizer/i18n/
context=Magento_GoogleTagManager............path=/i18n/
context=Magento_GroupedProduct............path=/home/user/magento/vendor/magento/module-grouped-product/i18n/
context=Magento_GroupedProductStaging............path=/i18n/
context=Magento_ImportExport............path=/home/user/magento/vendor/magento/module-import-export/i18n/
context=Magento_Indexer............path=/home/user/magento/vendor/magento/module-indexer/i18n/
context=Magento_Integration............path=/home/user/magento/vendor/magento/module-integration/i18n/
context=Magento_Invitation............path=/i18n/
context=Magento_LayeredNavigation............path=/home/user/magento/vendor/magento/module-layered-navigation/i18n/
context=Magento_Logging............path=/i18n/
context=Magento_Marketplace............path=/home/user/magento/vendor/magento/module-marketplace/i18n/
context=Magento_MediaStorage............path=/home/user/magento/vendor/magento/module-media-storage/i18n/
context=Magento_MessageQueue............path=/i18n/
context=Magento_Msrp............path=/home/user/magento/vendor/magento/module-msrp/i18n/
context=Magento_MultipleWishlist............path=/i18n/
context=Magento_Multishipping............path=/home/user/magento/vendor/magento/module-multishipping/i18n/
context=Magento_MysqlMq............path=/i18n/
context=Magento_NewRelicReporting............path=/home/user/magento/vendor/magento/module-new-relic-reporting/i18n/
context=Magento_Newsletter............path=/home/user/magento/vendor/magento/module-newsletter/i18n/
context=Magento_OfflinePayments............path=/home/user/magento/vendor/magento/module-offline-payments/i18n/
context=Magento_OfflineShipping............path=/home/user/magento/vendor/magento/module-offline-shipping/i18n/
context=Magento_PageCache............path=/home/user/magento/vendor/magento/module-page-cache/i18n/
context=Magento_Payment............path=/home/user/magento/vendor/magento/module-payment/i18n/
context=Magento_Paypal............path=/home/user/magento/vendor/magento/module-paypal/i18n/
context=Magento_PersistentHistory............path=/i18n/
context=Magento_Persistent............path=/home/user/magento/vendor/magento/module-persistent/i18n/
context=Magento_PricePermissions............path=/i18n/
context=Magento_ProductAlert............path=/home/user/magento/vendor/magento/module-product-alert/i18n/
context=Magento_ProductVideo............path=/home/user/magento/vendor/magento/module-product-video/i18n/
context=Magento_ProductVideoStaging............path=/i18n/
context=Magento_PromotionPermissions............path=/i18n/
context=Magento_Quote............path=/home/user/magento/vendor/magento/module-quote/i18n/
context=Magento_Reminder............path=/i18n/
context=Magento_Reports............path=/home/user/magento/vendor/magento/module-reports/i18n/
context=Magento_Review............path=/home/user/magento/vendor/magento/module-review/i18n/
context=Magento_ReviewStaging............path=/i18n/
context=Magento_Reward............path=/i18n/
context=Magento_Rma............path=/i18n/
context=Magento_Rss............path=/home/user/magento/vendor/magento/module-rss/i18n/
context=Magento_Rule............path=/home/user/magento/vendor/magento/module-rule/i18n/
context=Magento_SalesArchive............path=/i18n/
context=Magento_Sales............path=/home/user/magento/vendor/magento/module-sales/i18n/
context=Magento_SalesRule............path=/home/user/magento/vendor/magento/module-sales-rule/i18n/
context=Magento_SalesRuleStaging............path=/i18n/
context=Magento_SalesSequence............path=/home/user/magento/vendor/magento/module-sales-sequence/i18n/
context=Magento_ScalableCheckout............path=/i18n/
context=Magento_ScalableInventory............path=/i18n/
context=Magento_ScheduledImportExport............path=/i18n/
context=Magento_Search............path=/home/user/magento/vendor/magento/module-search/i18n/
context=Magento_SearchStaging............path=/i18n/
context=Magento_Security............path=/home/user/magento/vendor/magento/module-security/i18n/
context=Magento_SendFriend............path=/home/user/magento/vendor/magento/module-send-friend/i18n/
context=Magento_Shipping............path=/home/user/magento/vendor/magento/module-shipping/i18n/
context=Magento_Sitemap............path=/home/user/magento/vendor/magento/module-sitemap/i18n/
context=Magento_Solr............path=/i18n/
context=Magento_Staging............path=/i18n/
context=Magento_Store............path=/home/user/magento/vendor/magento/module-store/i18n/
context=Magento_Support............path=/i18n/
context=Magento_Swatches............path=/home/user/magento/vendor/magento/module-swatches/i18n/
context=Magento_TargetRule............path=/i18n/
context=Magento_TaxImportExport............path=/home/user/magento/vendor/magento/module-tax-import-export/i18n/
context=Magento_Tax............path=/home/user/magento/vendor/magento/module-tax/i18n/
context=Magento_Theme............path=/home/user/magento/vendor/magento/module-theme/i18n/
context=Magento_Translation............path=/home/user/magento/vendor/magento/module-translation/i18n/
context=Magento_Ui............path=/home/user/magento/vendor/magento/module-ui/i18n/
context=Magento_Ups............path=/home/user/magento/vendor/magento/module-ups/i18n/
context=Magento_UrlRewrite............path=/home/user/magento/vendor/magento/module-url-rewrite/i18n/
context=Magento_User............path=/home/user/magento/vendor/magento/module-user/i18n/
context=Magento_Usps............path=/home/user/magento/vendor/magento/module-usps/i18n/
context=Magento_Variable............path=/home/user/magento/vendor/magento/module-variable/i18n/
context=Magento_Vault............path=/home/user/magento/vendor/magento/module-vault/i18n/
context=Magento_VersionsCms............path=/i18n/
context=Magento_VisualMerchandiser............path=/i18n/
context=Magento_Webapi............path=/home/user/magento/vendor/magento/module-webapi/i18n/
context=Magento_WebapiSecurity............path=/home/user/magento/vendor/magento/module-webapi-security/i18n/
context=Magento_WebsiteRestriction............path=/i18n/
context=Magento_Weee............path=/home/user/magento/vendor/magento/module-weee/i18n/
context=Magento_Widget............path=/home/user/magento/vendor/magento/module-widget/i18n/
context=Magento_Wishlist............path=/home/user/magento/vendor/magento/module-wishlist/i18n/
context=Magento_Worldpay............path=/i18n/

If we look further, we find that the method buildPathToLocaleDirectoryByContext() is defined at setup/src/Magento/Setup/Module/I18n/Context.php:99:

    /**
     * Get paths by context
     *
     * @param string $type
     * @param array $value
     * @return string
     * @throws \InvalidArgumentException
     */
    public function buildPathToLocaleDirectoryByContext($type, $value)
    {
        switch ($type) {
            case self::CONTEXT_TYPE_MODULE:
                $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $value);
                break;
            case self::CONTEXT_TYPE_THEME:
                $path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $value);
                break;
            case self::CONTEXT_TYPE_LIB:
                $path = BP . '/lib/web';
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Invalid context given: "%s".', $type));
        }
        return $path . '/' . self::LOCALE_DIRECTORY . '/';
    }

In this case we're always hitting the first case, so looking further into componentRegistrar->getPath(), we have vendor/magento/framework/Component/ComponentRegistrar.php:72:

    public function getPath($type, $componentName)
    {
        self::validateType($type);
        return isset(self::$paths[$type][$componentName]) ? self::$paths[$type][$componentName] : null;
    }

which suggests that the modules have not been registered by calling the register() method.

NadiyaS commented 8 years ago

Hi @thomvanderboon , @biojppm , thank you for reporting this issue. Internal tiket MAGETWO-57820 was created.

piotrekkaminski commented 8 years ago

Increased priority as it is a blocker for translations.

biojppm commented 8 years ago

@piotrekkaminski ping is there an ETA for this? or a quick fix which I can apply on my side?

Ctucker9233 commented 8 years ago

I'd like to know if there is an ETA on delivering this in a patch, or how I should apply it if I need it now. Thanks.

afavata commented 8 years ago

any news on this issue????

NadiyaS commented 8 years ago

Hi, this issue was fixed and delivered to develop branch. See commits cc5cd56, cd5bb2d. The issue is closed as resolved.

Ctucker9233 commented 8 years ago

@NadiyaS do these commits work for 2.1.2 or is there a port coming?

NadiyaS commented 8 years ago

Hi @Ctucker9233 , these commits are not in 2.1.2. But the fix is planned to be in 2.1.x. I do not know concrete version right now.

afavata commented 8 years ago

Hi @NadiyaS this issue is affecting many people wordwide... non permitting to be online in the proprer local language. Is it possible to request a very urgent release for 2.1.2 to resolve this issue. thanks

Alex

NadiyaS commented 8 years ago

Hi @afavata , if this issue is very critical for you, you can use our fix for now (see commits cc5cd56 and cd5bb2d, so you need to do changes in 2 files: vendor/magento/magento2-base/setup/src/Magento/Setup/Module/I18n/Context.php and vendor/magento/magento2-base/setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php). The priority of this issue was estimated as very high, so we can expect this fix in one of the next port for 2.1 version.

afavata commented 8 years ago

Hi @NadiyaS thank you for your quick reply. I followed your suggestion changing the two files as follow: I have copied the whole content of file Context.php and AbstractFile.php both at version cd5bb2d on Sep 7 and pasted respectively in

vendor/magento/magento2-base/setup/src/Magento/Setup/Module/I18n/Context.php
and 
vendor/magento/magento2-base/setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php.

Then I submitted the command: bin/magento i18n:pack -m replace -d source_it_IT.csv it_IT

Result... a folder i18n was created in the system root / with inside it_IT.csv. Obviously this is not what expected from the above procedure.

Any other suggestions? Thank you

Alex

slackerzz commented 7 years ago

any news?

afavata commented 7 years ago

Not yet!!!.....

Ctucker9233 commented 7 years ago

Any chance the fix will be in 2.1.3?

siliconalchemy commented 7 years ago

"The priority of this issue was estimated as very high, so we can expect this fix in one of the next port for 2.1 version."

6 months later and several point releases later and this fix still isn't place. Guess the priority isn't that high..

thomvanderboon commented 7 years ago

There is a workarround for this issue. Create the languagepack and keep the translation in one file

https://github.com/magento/magento2/issues/2951#issuecomment-276552659

Thom

michel334 commented 7 years ago

this issue seems to be still present in 2.1.7 is there an ETA on the release?

davidalger commented 7 years ago

@michel334 Fixed on develop means it will be included in the next feature release. I.e. Magento 2.2 should have the fix. If there are fixes you would like to see back ported to 2.1 (i.e. where Magento only fixes on develop), feel free to back port the fix and submit a PR to the 2.1-develop branch.

korostii commented 7 years ago

@davidalger, your answer raises yet another question: what's the ETA on the release of 2.2? :)

michel334 commented 7 years ago

@davidalger thanks, live will be good in 2.2 :)

rodrigowebjump commented 7 years ago

This issue is also generated when you use an invalid translate context or left an empty space after context

"Customer not found! Verify your data","Cliente no encontrado! Verifique sus datos",module,Webjump_FirstAccess <-- space