Automatically importing XLIFF files for the Localization package

Hi,
I am working on a project and trying to use the Localization package in our workflow.
Here is situation:

  • developper exports a XLIFF file from the Localization package and gives it to the internal localization team
  • the localization team fills up the file with the missing data (different languages) but not using the Unity interface
  • the localization team saves the XLIFF file in same repo location where they picked it up
  • when the developer pulls the repo and starts Unity, the XLIFF modifications are not visible and he needs to manually import the XLIFF from the Unity menu

Question:
Is there a setting that exists or any scripting way to have unity automatically import all the XLIFF files that exist in the project without actually having someone doing it manually?

There is a scripting API that can be used to do this
https://docs.unity3d.com/Packages/com.unity.localization@1.1/api/UnityEditor.Localization.Plugins.XLIFF.Xliff.html

https://docs.unity3d.com/Packages/com.unity.localization@1.1/manual/XLIFF.html

Thanks Karl.
Yes I am aware of those APIs. My question is more related to when I load the project in Unity, is it possible to have the XLIFF automatically imported without me running a particular script in order to import the XLIFF file?

I have found this reference : Unity - Manual: Running Editor Script Code on Launch
It looks that this would actually allow me to use the XLIFF scripting API to update the project with the newly modified XLIFF files.
If you have any other suggestions please let me know

Yes that would work or you could also use a scripted importer for the xliff file extension.

Thanks Karl,
That was very helpful

is the xliff api only for editor mode? could I have a MonoBehaviour load an xliff file at runtime in the awake/start functionality?

I have found the Xliff.ImportFile from UnityEngine. Would this be the equivalent to the Editor one?

Xliff support is editor only, it won’t work in the player. Why do you need it at runtime?

I am trying to find a process to make the Xliff import automatic and reduce the impact on manually import it and then save all the modified assets in the git repo.
Any suggestions would be greatly appreciated.

You can use the Xliff Api to import through script.
https://docs.unity3d.com/Packages/com.unity.localization@1.1/manual/XLIFF.html#xliff-api

If you want it to be automatic then you could try making a scripted importer for xliff files which will trigger the import and then save the assets.

https://docs.unity3d.com/ScriptReference/AssetImporters.ScriptedImporter.html

Thanks a lot. that is actually what I did but wasnt sure if there are any other ways.
I used scripter importer to trigger the import of xliff files when modified and while the user is working on the project.
I also used the xliff api to trigger from command line updates when the xliff are modified outside Unity. this way when someone updates xliff file they will need to call the a script from cmd and update the assets. Then they can commit the modified files to the repo for others to use

1 Like

Are you saying it’s not possible to update/import Xliff at runtime at all? I’m currently investigating switching to Unity Localization package, but in our production environment, we rely on pulling in the latest translations at app start up. This allows translations to be updated without requiring a new build.

We don’t support doing this outside of the editor at the moment. For updating during app start we recommend using the content update approach. We do also have API that lets you update or provide tables at runtime if you want to provide your own custom provider, such as reading xliff however our xliff parser is editor only so you would need to provide your own.

https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Scripting.html#custom-table-loading
https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Scripting.html#applying-changes-to-a-table-after-the-game-is-built