Skip to content

Conversation

nirvn
Copy link
Member

@nirvn nirvn commented Sep 12, 2025

This PR implements support for localized / translated project files so that QField can speak a lot of languages too (background reading: https://www.opengis.ch/2018/09/11/qgis-speaks-a-lot-of-languages/). This also works with cloud projects, which is reallly nice.

Contrary to QGIS, we will always display a localized project if the _XX.qm file is present (i.e., we don't require users to overwrite / specify a locale). It will respect the phone / device's OS locale, or the one specified in QField settings panel.

Implements / fixes #5670

@qfield-fairy
Copy link
Collaborator

@nirvn nirvn changed the title Project translation Project localization/translation support Sep 12, 2025
@nirvn
Copy link
Member Author

nirvn commented Sep 12, 2025

Since we do expose and rely on project titles and other layer metadata quite a lot in our UI, this was a very good reason to improve project translation upstream and add support for the localization of basic project and layer metadata. The result is here: qgis/QGIS#63168 🥳

Comment on lines +280 to +304
else if ( suffix == QStringLiteral( "qgs" ) || suffix == QStringLiteral( "qgz" ) )
{
QRegularExpression re( QStringLiteral( "(.*)_[A-Za-z]{2}" ) );
QRegularExpressionMatch match = re.match( fi.completeBaseName() );
if ( match.hasMatch() )
{
if ( items.contains( QStringLiteral( "%1.qgs" ).arg( match.captured( 1 ) ), Qt::CaseInsensitive ) || items.contains( QStringLiteral( "%1.qgz" ).arg( match.captured( 1 ) ), Qt::CaseInsensitive ) )
{
// Skip translated project, users should always use the original project
continue;
}
}
}
else if ( suffix == QStringLiteral( "zip" ) )
{
if ( item.endsWith( QStringLiteral( "_attachments.zip" ), Qt::CaseInsensitive ) )
{
const QString reducedItemName = item.mid( 0, item.size() - 16 );
if ( items.contains( QStringLiteral( "%1.qgs" ).arg( reducedItemName ), Qt::CaseInsensitive ) || items.contains( QStringLiteral( "%1.qgz" ).arg( reducedItemName ), Qt::CaseInsensitive ) )
{
// Skip project attachments sidecar file
continue;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirvn , could you please elaborate a bit more on what the code is doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohsenD98 , it's skipping sidecar files that QGIS generates alongside the main .qgs project file. The sidecar files are of no use and should only be accessed by opening the main project.qgs file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support of qm translation file
3 participants