joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.76k stars 3.65k forks source link

Getting a Joomla 4 API component to work with language files #41944

Closed cappuccinonet closed 7 months ago

cappuccinonet commented 1 year ago

Steps to reproduce the issue

When programming a component for an API in Joomla 4, the config contains the following language file definitions:

<api>
    <files folder="api">
        <folder>src</folder>
    </files>
    <languages folder="api">
        <language tag="en-GB">language/en-GB/com_mycomponent.ini</language>
        <language tag="en-GB">language/en-GB/com_mycomponent.sys.ini</language>
    </languages>
</api>

The component installs without errors, but the language files in the folder /api/language/en-GB/* of the component aren't copied to the folder /api/language/en-GB/ as described here https://www.dionysopoulos.me/book/com-lang.html.

When I copy the language files manually, they are interpreted correctly. Languages other than en-GB do not seem to work.

Expected result

All language files within the element should be copied to the /api/language folder.

Actual result

System information (as much as possible)

Joomla 4.3.4

Additional comments

Fedik commented 1 year ago

All language files within the element should be copied to the /api/language folder.

Not really. It was like that long time ago.

Nowaday all language files should be within component: for Site components/com_example/language, for API api/components/com_example/language, for Administrator administrator/components/com_example/language,

Same for Plugins and Modules

brianteeman commented 1 year ago

@Fedik sorry that is not correct

richard67 commented 1 year ago

@cappuccinonet Could you post the content of the manifest XML of that component?

cappuccinonet commented 1 year ago

@richard67 Just fixed the markup to show up the code. Before opening this thread I posted the question on Stackexchange


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41944.

richard67 commented 1 year ago

Where in the zip file of the package are the language files located? Reading this answer on Stackexchange I would assume they are located inside the "api" folder in the zip, not in a subfolder of that. Or do you have them inside folder "api/language" in the zip, and the "api" folder is at the first level inside the zip? Then your XML should be:

<api>
    <files folder="api">
        <folder>src</folder>
    </files>
    <languages folder="api/language">
        <language tag="en-GB">language/en-GB/com_mycomponent.ini</language>
        <language tag="en-GB">language/en-GB/com_mycomponent.sys.ini</language>
    </languages>
</api>

Not sure if that will work, but that's how I understand that answer on Stackexchange.

cappuccinonet commented 1 year ago

They are located here:


<extension> 
   ...
   <namespace path="src">MyCompany\Component\MyExtension</namespace>
   ...
   <administration>
      <files folder="admin">
         ...
      </files>
      <languages folder="admin">
        <language tag="en-GB">language/en-GB/com_mycomponent.ini</language>
        <language tag="en-GB">language/en-GB/com_mycomponent.sys.ini</language>
      </languages>
   <administration>
   ...
   <api>
      <files folder="api">
         <folder>src</folder>
      </files>
      <languages folder="api/language">
         <language tag="en-GB">language/en-GB/com_mycomponent.ini</language>
         <language tag="en-GB">language/en-GB/com_mycomponent.sys.ini</language>
      </languages>
   </api>
   ...
</extension>
```<hr /><sub>This comment was created with the <a href="https://github.com/joomla/jissues">J!Tracker Application</a> at <a href="https://issues.joomla.org/tracker/joomla-cms/41944">issues.joomla.org/tracker/joomla-cms/41944</a>.</sub>
cappuccinonet commented 1 year ago

The files itself are located inside the zip like this:

/admin/language/en-GB
/api/language/en-GB


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41944.

brianteeman commented 1 year ago
      <languages folder="api/language">
         <language tag="en-GB">en-GB/com_mycomponent.ini</language>
         <language tag="en-GB">en-GB/com_mycomponent.sys.ini</language>
      </languages>
cappuccinonet commented 1 year ago

@brianteeman I tried that too, but it failed to work.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41944.

Fedik commented 1 year ago

Fedik sorry that is not correct

I mean, it what is prefered. You just place your language under component, and all works:

<administration>
  <files folder="admin">
    <folder>language</folder>
    ...    
  </files>
<administration>

<api>
  <files folder="api">
      <folder>language</folder>
      ...
  </files>
</api>

<files folder="site">
  <folder>language</folder>
  ...
</files>

There was a discussion here some years ago, but it will be hard to find. No practical reasons to place extension language files globally.

Fedik commented 1 year ago

I tried that too, but it failed to work.

What @brianteeman suggested should work, maybe one of paths is incorect, you also can try other way around:

<api>
      <files folder="api">
         <folder>src</folder>
      </files>
      <languages folder="api">
         <language tag="en-GB">language/en-GB/com_mycomponent.ini</language>
         <language tag="en-GB">language/en-GB/com_mycomponent.sys.ini</language>
    </languages>
</api>

But I would suggest to try what I wrote in previous comment, it much more clean and easy.

heelc29 commented 7 months ago

@cappuccinonet Could you please test #43152?

richard67 commented 7 months ago

Closing as having a pull request. Please test #43152 . Thanks in advance.