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

feat: add localization for meta endpoints #288

Merged
merged 5 commits into from
May 10, 2022

Conversation

FiboApe
Copy link
Collaborator

@FiboApe FiboApe commented May 2, 2022

Description

Adds localization to the sdk, accepting

Related Issue

Motivation and Context

We want to show localized strings for strategies and tokens data on any provided rfrom the sdk

How Has This Been Tested?

Manually and some unit tests

Screenshots (if appropriate):

(Screenshot for initializing sdk with 'es' locale while main application is in 'en' locale)
Screenshot 2022-05-02 at 17 15 55

@@ -151,7 +151,8 @@ export class StrategyInterface<T extends ChainId> extends ServiceInterface<T> {
const metadata: StrategyMetadata = {
address: strategy.address,
name: metadatum?.name || strategy.name || "Strategy",
description: metadatum?.description ?? "I don't have a description for this strategy yet",
description:
metadatum?.localization[this.ctx.locale]?.description ?? "I don't have a description for this strategy yet",
Copy link
Contributor

Choose a reason for hiding this comment

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

fallback to the english description first instead of "I don't have a description for this strategy yet"? Since that's in english anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed if we are certain that English is always available.

Otherwise, I'd say "No description available" or something more generic.

Copy link
Contributor

@jstashh jstashh May 4, 2022

Choose a reason for hiding this comment

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

metadatum.description should always be available and in english, so I'm confident we can fallback to that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed on d53eb2f

src/context.ts Outdated Show resolved Hide resolved
src/types/metadata.ts Outdated Show resolved Hide resolved
src/services/meta.ts Outdated Show resolved Hide resolved
src/services/meta.ts Outdated Show resolved Hide resolved
src/types/metadata.ts Outdated Show resolved Hide resolved
property: T;
locale: Locale;
fallback: string;
}): string => obj?.localization[locale]?.description ?? (obj && obj[property]) ?? fallback;
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a shame that we've lost the fallback to english here first, not sure how messy that would make the code to add it back, but I think it would be better from a product perspective

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mean now it's part of whoever wants to localize a string to set a fallback for it, which in these cases would be the original english string, and fallback is always required so it is needed to provide that string

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add it here, but we'd need a fallback object with all the fallbacks, and then if a fallback is not provided we default to English. I think that makes sense in order to have it centralised.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isnt the english text defaulted in obj && property && obj[property] ? From what I see in yearn-meta, that is how it has been structured, and should always exist.

Copy link
Contributor

@xgambitox xgambitox May 10, 2022

Choose a reason for hiding this comment

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

Or you mean something like:

obj?.localization[locale]?.description ?? obj?.localization['en']?.description ?? (obj && property && obj[property]) ?? fallback

?

Copy link
Contributor

@karelianpie karelianpie May 10, 2022

Choose a reason for hiding this comment

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

I think what @jstashh was referring to is that we shouldn't need a required fallback prop and it would just fallback to English in the SDK. If the fallback prop is given then it would override that default fallback.

Copy link
Contributor

Choose a reason for hiding this comment

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

obj?.localization[locale]?.description ?? obj?.localization['en']?.description ?? (obj && property && obj[property]) ?? fallback

@xgambitox yes something like that, since we know english will always be there and that it would probably be more useful than a generic error message (I don't have a description for this strategy yet)

Copy link
Contributor

Choose a reason for hiding this comment

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

not a blocker though - let's merge this to move forwards

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, will merge then, and if it becomes an issue we will revisit it

Copy link
Contributor

@karelianpie karelianpie left a comment

Choose a reason for hiding this comment

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

LGTM, I do agree with @jstashh that we could have a defaultFallback if none is provided.

@xgambitox xgambitox merged commit 14af138 into yearn:master May 10, 2022
jstashh pushed a commit that referenced this pull request May 31, 2022
* feat: add localization for meta endpoints

* test: add tests for token localization

* fix: fix styling

* feat: pr feedback

* fix: pr feedback
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.

4 participants