Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining missing mobile translations #857

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

tom-anders
Copy link
Contributor

This solves #753

I didn't add any translation for the Puzzle Storm description, since the string is copied from lila (which does not have a translation yet either)

Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

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

Thanks.

There is also the Join a game from the custom game creation screen that is missing.

lib/src/view/analysis/analysis_position_choice_screen.dart Outdated Show resolved Hide resolved
@tom-anders
Copy link
Contributor Author

Thanks.

There is also the Join a game from the custom game creation screen that is missing.

Ah, we already have a string for that actually, apparently I just forgot to use it

@veloce
Copy link
Contributor

veloce commented Jul 18, 2024

@tom-anders can you solve the conflicts please?

@@ -527,7 +527,7 @@ class _HelloWidget extends ConsumerWidget {
),
const SizedBox(width: 5.0),
Text(
'Hello${user != null ? ', ' : ''}',
'${context.l10n.mobileHello}${user != null ? ', ' : ''}',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@veloce This should probably be fine for most languages, but I'm sure there are some languages where "Hello, %s" does not make any sense, we might want to revisit this at some point

Copy link
Contributor

Choose a reason for hiding this comment

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

@tom-anders that is because we use the UserFullNameWidget.

Now that I think of it we should make it right from the start and have a parameterised message such as helloX : Hello, <name>.

We can adapt the HelloWidget later to show the flair for instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so the string is now 'Hello %s' and I added a special case in the translation generation, making sure that the %s is not converted to a function parameter. This way, we can instead split the (localized) string at '%s' and put the UserNameWidget between the two resulting parts.

@tom-anders
Copy link
Contributor Author

@tom-anders can you solve the conflicts please?

Done 👍

veloce
veloce previously approved these changes Jul 23, 2024
@veloce veloce dismissed their stale review July 23, 2024 07:40

I didn't see the Hello, X thing.

@tom-anders tom-anders force-pushed the mobileTranslations branch 2 times, most recently from e42761c to 4dffeb9 Compare July 24, 2024 21:07
style: style,
),
if (user != null) UserFullNameWidget(user: user, style: style),
if (user != null && greetingParts.length == 2) ...[
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about this. Is the greetingParts.length always 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, according to the flutter docs:

A non-empty match at the start or end of the string, or after another match, is not treated specially, and will introduce empty substrings in the result

So we'll always get 2 here, as long as '%s' is somewhere in the string, including start and end. (If not, it's a translation issue, the comment says to always include the %s)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a common use case (inclusion of a widget instead of string in a translation) so it should be factored out in a utility function.

And this function should have unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes good point, will do 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, added a utility function

IList<Widget> replaceL10nPlaceholderWithWidget<T extends Widget>(
  String Function(String) l10nWithReplacement,
  T widget, {
  TextStyle? textStyle,
})

To avoid empty text widgets, this now also catches the case where the placeholder is at start the start or end and only adds one instead of two Text Widgets in that case

@tom-anders tom-anders force-pushed the mobileTranslations branch 3 times, most recently from b01a34c to 88c2ead Compare July 25, 2024 21:17
Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

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

One remaining change about the signature of the utility function and we're good I think :)

lib/src/utils/l10n.dart Outdated Show resolved Hide resolved
lib/src/utils/l10n.dart Outdated Show resolved Hide resolved
@veloce veloce merged commit d4cb356 into lichess-org:main Jul 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants