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

Various improvements #56

Merged
merged 2 commits into from
Jul 7, 2023
Merged

Various improvements #56

merged 2 commits into from
Jul 7, 2023

Conversation

stelabouras
Copy link
Collaborator

Improve CDSHandler push logic

The pushTranslations() method now returns a secondary array of Error
objects in the completion handler that represents the generated warnings
during the processing of the source strings that are non-fatal but can
be of interest to the developer.

This change introduces a new enum (TXCDSWarning) that hosts those
warnings, like duplicate source string and empty key detection.

The pushTranslations() logic has been improved by implementing the
following changes:

  • serializeTranslations() is now a private static method as it does
    not need to look into the state of the CDSHandler instance.
  • That method now returns a tuple that includes a Result<Data> object
    as the first member, revealing whether the serialization
    was successful, thus offering the Data object, or a failure, thus
    offering a Error object for further propagation and an array of
    TXCDSWarning objects for any generated warnings during the processing
    of the source strings.
  • The pushTranslations() implementation has been split so that it's
    easier to be read. The new method that performs the asynchronous network
    operation is now separate (pushData()) and propagates the generated
    warnings to the pollJobStatus() method.
  • Any error logging has been removed in favor of the list of Error
    objects in the completion handler. The logging is now a responsibility
    of the consumer.

Introduce t() method

A new public static method has been introduced in the TXNative class,
allowing developers to programmatically trigger the translation
mechanism of Transifex SDK in cases where this is not supported.

For example, in SwiftUI, where the swizzling mechanism of Transifex SDK
does currently work, developers can replace views like this:

Text("test string")

with this:

Text(TXNative.t("test string"))

The method uses the default locale that Transifex SDK has been
configured with.

Note: If you want to change the current locale used by the
SwiftUI preview to test different locales, click on the 'Product' menu
item and then visit 'Scheme' > 'Edit Scheme...' > 'Run' > 'Options' >
'App Language' and pick the language you want to test.

The `pushTranslations()` method now returns a secondary array of `Error`
objects in the completion handler that represents the generated warnings
during the processing of the source strings that are non-fatal but can
be of interest to the developer.

This change introduces a new enum (`TXCDSWarning`) that hosts those
warnings, like duplicate source string and empty key detection.

The `pushTranslations()` logic has been improved by implementing the
following changes:

* `serializeTranslations()` is now a private static method as it does
not need to look into the state of the `CDSHandler` instance.
* That method now returns a tuple that includes a `Result<Data>` object
as the first member, revealing whether the serialization
was successful, thus offering the `Data` object, or a failure, thus
offering a `Error` object for further propagation and an array of
`TXCDSWarning` objects for any generated warnings during the processing
of the source strings.
* The `pushTranslations()` implementation has been split so that it's
easier to be read. The new method that performs the asynchronous network
operation is now separate (`pushData()`) and propagates the generated
warnings to the `pollJobStatus()` method.
* Any error logging has been removed in favor of the list of `Error`
objects in the completion handler. The logging is now a responsibility
of the consumer.
A new public static method has been introduced in the `TXNative` class,
allowing developers to programmatically trigger the translation
mechanism of Transifex SDK in cases where this is not supported.

For example, in SwiftUI, where the swizzling mechanism of Transifex SDK
does currently work, developers can replace views like this:

```
Text("test string")
```

with this:

```
Text(TXNative.t("test string"))
```

The method uses the default locale that Transifex SDK has been
configured with.

Note: If you want to change the current locale used by the
SwiftUI preview to test different locales, click on the 'Product' menu
item and then visit 'Scheme' > 'Edit Scheme...' > 'Run' > 'Options' >
'App Language' and pick the language you want to test.
@stelabouras stelabouras marked this pull request as ready for review July 7, 2023 10:50
@stelabouras stelabouras requested a review from n1k0sv July 7, 2023 10:50
@n1k0sv n1k0sv merged commit 07da18a into devel Jul 7, 2023
@n1k0sv n1k0sv deleted the stelios/various-improvements branch July 7, 2023 11:36
@txsentinel txsentinel mentioned this pull request Jul 7, 2023
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