Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: jsx on December 17, 2018, 11:38:39 AM

Title: Which version of the XML should I use?
Post by: jsx on December 17, 2018, 11:38:39 AM
Hey,

I created a translation for some modification and I would like to know which version of the XML code should I use in package-info? Both versions of the code are correct, because the translation will install correctly. But which version better to use? I am asking about it for the knowledge.

<install>
<modification format="xml" type="file">install_polish-utf8.xml</modification>
</install>

<uninstall>
<modification type="file" reverse="true">install_polish-utf8.xml</modification>
</uninstall>


Second version:

<install for="2.0 - 2.0.99">
<modification type="file">install_polish-utf8.xml</modification>
</install>

<uninstall for="2.0 - 2.0.99">
<modification type="file" reverse="true">install_polish-utf8.xml</modification>
</uninstall>
Title: Re: Which version of the XML should I use?
Post by: Arantor on December 17, 2018, 11:47:09 AM
The latter as it covers the versions that should be installed against. If you need to do something different in 2.1 for example you can have a block of just 2.1 install instructions (the block you posted is just for 2.0)
Title: Re: Which version of the XML should I use?
Post by: jsx on December 17, 2018, 01:03:34 PM
If I understood correctly, I must use the second code, right?

Title: Re: Which version of the XML should I use?
Post by: Arantor on December 17, 2018, 01:34:47 PM
Both work, but the second is better because you can say which versions of SMF you want. The first will try to install on anything.
Title: Re: Which version of the XML should I use?
Post by: jsx on December 17, 2018, 02:13:59 PM
Thanks for the explanation. I do not need to use the file name install_polish-utf8.xml can be just polish-utf8.xml?
Title: Re: Which version of the XML should I use?
Post by: Arantor on December 17, 2018, 02:28:24 PM
As long as the file in the zip file is called the same as the XML points to, you can call it whatever you like.
Title: Re: Which version of the XML should I use?
Post by: jsx on December 17, 2018, 02:59:42 PM
The name of the modification package is: Change All Subjects.zip
The name of the package with the translation is: Change_All_Subjects_PL.zip
The name of the file with the translation is: install_polish-utf8.xml or polish-utf8.xml

And the translation works fine.
Title: Re: Which version of the XML should I use?
Post by: Arantor on December 17, 2018, 03:08:37 PM
i don't know how I can explain this any other way.

You can call the file whatever you like. SMF does not care what filename you use at all. All it cares is that the package info file says to use a file, and that the file exists. Any name the file has is for human use only.
Title: Re: Which version of the XML should I use?
Post by: jsx on December 17, 2018, 03:58:42 PM
All right, topic solved.
Title: Re: Which version of the XML should I use?
Post by: jsx on January 27, 2019, 01:22:01 PM
I have a question again.

1. Why in this first installer I can install the translation for the modification that is in the XML file, and the PHP file will not be installed through this installer.

Example:

polish-utf8.xml - this translation will be installed correctly

Announcements.polish-utf8.php - this translation not will be installed correctly, occurs modification parsing error.

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<name></name>
<id></id>
<version>1.0</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
<modification type="file">polish-utf8.xml</modification>
</install>

<uninstall for="2.0 - 2.0.99">
<modification type="file" reverse="true">polish-utf8.xml</modification>
</uninstall>

</package-info>


2. Through this installer, the translation that is in the PHP file will install correctly.

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
   <name></name>
   <id></id>
   <type>modification</type>
   <version>1.0</version>
   <install>
      <require-file name="Announcements.polish-utf8.php" destination="$languagedir" />
   </install>
   
   <uninstall>
      <remove-file name="$languagedir/Announcements.polish-utf8.php" />
   </uninstall>
</package-info>
Title: Re: Which version of the XML should I use?
Post by: SychO on January 27, 2019, 01:46:39 PM
because in the first code you didn't tell the package manager to extract the file to $languagedir ?

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<name></name>
<id></id>
<version>1.0</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
<modification type="file">polish-utf8.xml</modification>
<require-file name="Announcements.polish-utf8.php" destination="$languagedir" />
</install>

<uninstall for="2.0 - 2.0.99">
<modification type="file" reverse="true">polish-utf8.xml</modification>
<remove-file name="$languagedir/Announcements.polish-utf8.php" />
</uninstall>

</package-info>
Title: Re: Which version of the XML should I use?
Post by: nour on January 29, 2019, 07:27:59 AM
Quote from: Arantor on December 17, 2018, 01:34:47 PM
Both work, but the second is better because you can say which versions of SMF you want. The first will try to install on anything.

I totally agree,
But if youproject that your code is not version dependant, i.e. it works with all future versions than both codes become the same thing.
Title: Re: Which version of the XML should I use?
Post by: Arantor on January 29, 2019, 07:30:20 AM
I hate to be that guy, but that is massively more complex than you can possibly imagine for anything non trivial in SMF's world.
Title: Re: Which version of the XML should I use?
Post by: jsx on January 30, 2019, 07:02:58 AM
@SychO

Thanks for clarification. But these lines can be removed from this code, because the only file with the translation is this file Announcements.polish-utf8.php. Right?

<modification type="file">polish-utf8.xml</modification>

<modification type="file" reverse="true">polish-utf8.xml</modification>


And if the translation was only in the file eg polish-utf8.xml, then only these lines must be in this installer, right?

Now everything is correct in these installers?

Installer for translation in a PHP file:

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<name></name>
<id></id>
<version>1.0</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
<require-file name="Announcements.polish-utf8.php" destination="$languagedir" />
</install>

<uninstall for="2.0 - 2.0.99">
<remove-file name="$languagedir/Announcements.polish-utf8.php" />
</uninstall>

</package-info>


Installer for translation in a XML file:

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<name></name>
<id></id>
<version>1.0</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
<modification type="file">polish-utf8.xml</modification>
</install>

<uninstall for="2.0 - 2.0.99">
<modification type="file" reverse="true">polish-utf8.xml</modification>

</uninstall>

</package-info>
Title: Re: Which version of the XML should I use?
Post by: SychO on January 30, 2019, 01:10:36 PM
I have no idea what it is you're trying to do exactly
Title: Re: Which version of the XML should I use?
Post by: jsx on February 10, 2019, 02:37:15 PM
Quote from: SychO on January 30, 2019, 01:10:36 PM
I have no idea what it is you're trying to do exactly

There are such modifications SMF that contain a language file in XML. So, which should I use the installer to install the translation that is contained in the XML file?

This?

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<name></name>
<id></id>
<version>1.0</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
<modification type="file">polish-utf8.xml</modification>
</install>

<uninstall for="2.0 - 2.0.99">
<modification type="file" reverse="true">polish-utf8.xml</modification>

</uninstall>

</package-info>


Or this one?

<?xml version="1.0"?>
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<name></name>
<id></id>
<version>1.0</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
<require-file name="polish-utf8.xml" destination="$languagedir" />
</install>

<uninstall for="2.0 - 2.0.99">
<remove-file name="$languagedir/polish-utf8.xml" />
</uninstall>

</package-info>


And there are such modifications SMF that contain a language file in PHP. So, which should I use the installer to install the translation that is contained in the PHP file? The first or the second code?
Title: Re: Which version of the XML should I use?
Post by: Arantor on February 10, 2019, 02:57:39 PM
You have confused yourself entirely with this. The second one doesn't work because you're not including language files, you're trying to include an XML file in to the languages areas, which SMF will ignore.

Adding a whole new file is cleaner but it requires you use loadLanguage() in your code to load the right thing.
Title: Re: Which version of the XML should I use?
Post by: SychO on February 10, 2019, 03:03:27 PM
In addition to what Arantor said,

If you use the first one, you can just add new text strings to Modifications.{lang}.php, as long as you know the right syntax. And you won't have to use loadLanguage()
Title: Re: Which version of the XML should I use?
Post by: jsx on February 10, 2019, 04:26:37 PM
In previous post I just gave an example.

This code will install the XML language file:

<install for="2.0 - 2.0.99">
<modification type="file">polish-utf8.xml</modification>
</install>


And this code will install the PHP language file:

<install for="2.0 - 2.0.99">
<require-file name="...polish-utf8.php" destination="$languagedir" />
</install>


I have one more question. Why is the content of the translation that is in the PHP file that was installed by the package is not located in the Modifications.polish-utf8.php file?
Title: Re: Which version of the XML should I use?
Post by: Arantor on February 10, 2019, 04:46:09 PM
Because you didn't tell it to? The package manager follows your instructions literally.

If you tell it to put a file into a folder, it's going to put a file into a folder. It doesn't know what the file is, it assumes that you know what you're doing.

If you want to edit Modifications-polish-utf8.php, write an XML file with search/add and use modification to include it.

If you want to add a completely new file, just include it and call loadLanguage() - if you have a lot of strings, better to do that than to clutter up Modifications, especially if you're adding a lot of stuff in a new section and you don't need to modify any files that way.


I'm honestly confused what is so difficult about this.
Title: Re: Which version of the XML should I use?
Post by: jsx on February 11, 2019, 04:03:14 AM
If I understand this correctly, the content of the translation that is in the PHP file does not go to the Modifications.polish-utf8.php file because is in the own file.

Example:

../languages/OharaYTEmbed.polish-utf8.php

Thank you for your patience. :)
Title: Re: Which version of the XML should I use?
Post by: SychO on February 11, 2019, 04:44:03 AM
no, that's not why

the file is added to the languages directory because you tell the package manager to do so
new language strings are added to Modifications.{lang}.php or any other language file, because you tell the package manager to execute a modification that does that work

you really need to read these
Package SDK: package-info.xml (http://www.simplemachines.org/community/index.php?topic=299669.0)
Package SDK: modification.xml (http://www.simplemachines.org/community/index.php?topic=299670.0)
Title: Re: Which version of the XML should I use?
Post by: Kindred on February 11, 2019, 05:08:14 PM
basically, I follow this rule of thumb.

If my mod adds under 20 text strings, I add those strings to the end of the modifications.language.php file....   if I'm going to add more, then I add my own separate file of strings just for the mod.


but doing that is two different commands in the mod install xml