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

Validate translation word in e2e test #1141

Closed
wants to merge 6 commits into from

Conversation

fullstackninja864
Copy link
Contributor

@fullstackninja864 fullstackninja864 commented Oct 22, 2021

What kind of PR is this?:

/kind feature

What this PR does / why we need it:

Currently we have 3 language support other than english. In this PR we are laying the foundation to test the translation words. To verify translation we have added e2e test check for all languages
to use this feature here is the steps to use

  1. Assign test id to the component containing text to be tested in this way
<Component testID='text-translation-<SCREEN_NAME>=<TEXT>

for eg:

<ThemedSectionTitle
  testID='text-translation-screens/BalancesScreen=PORTFOLIO'
  text={translate('screens/BalancesScreen', 'PORTFOLIO')}
/>
  1. In e2e test case use predefined cypress method as
cy.checkLnTextContent(<FUNCTION_TO_VISIT_SCREEN>, <SCREEN_NAME>)

for eg:

cy.checkLnTextContent((): void => {
  cy.getByTestID('bottom_tab_dex').click()
  cy.getByTestID('dex_guidelines_screen').should('exist')
}, 'screens/DexGuidelines')

Which issue(s) does this PR fixes?:

Fixes #855

Additional comments?:

Developer Checklist:

  • Read your code changes at least once
  • Tested on iOS/Android device (e.g, No crashes, library supported etc.)
  • No console errors on web
  • Tested on Light mode and Dark mode*
  • Your UI implementation visually matched the rendered design*
  • Unit tests*
  • Added e2e tests*
  • Added translations*

@codeclimate
Copy link

codeclimate bot commented Oct 22, 2021

Code Climate has analyzed commit 080b08b and detected 0 issues on this pull request.

View more on Code Climate.

@netlify
Copy link

netlify bot commented Oct 22, 2021

✔️ Deploy Preview for mobile-wallet-preview ready!

🔨 Explore the source changes: 080b08b

🔍 Inspect the deploy log: https://app.netlify.com/sites/mobile-wallet-preview/deploys/617253ac1eee370007fd0436

😎 Browse the preview: https://deploy-preview-1141--mobile-wallet-preview.netlify.app/

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #1141 (080b08b) into main (356eb52) will increase coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1141      +/-   ##
==========================================
+ Coverage   89.07%   89.20%   +0.12%     
==========================================
  Files         195      195              
  Lines        3341     3344       +3     
  Branches      739      740       +1     
==========================================
+ Hits         2976     2983       +7     
+ Misses        363      359       -4     
  Partials        2        2              
Impacted Files Coverage Δ
...screens/AppNavigator/screens/Dex/DexGuidelines.tsx 100.00% <ø> (ø)
...s/AppNavigator/screens/Balances/BalancesScreen.tsx 90.32% <100.00%> (+0.32%) ⬆️
shared/translations/index.ts 100.00% <100.00%> (ø)
mobile-app/app/components/BarCodeScanner.tsx 70.37% <0.00%> (+14.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 356eb52...080b08b. Read the comment docs.

@defichain-bot
Copy link
Contributor

defichain-bot commented Oct 22, 2021

Build preview for DeFiChain Wallet is ready!

Built with commit c75550c

https://expo.io/@defichain/wallet?release-channel=pr-preview-1141

@cypress
Copy link

cypress bot commented Oct 22, 2021



Test summary

225 0 1 0


Run details

Project wallet
Status Passed
Commit c75550c ℹ️
Started Oct 22, 2021 6:04 AM
Ended Oct 22, 2021 6:12 AM
Duration 08:03 💡
OS Linux Ubuntu - 20.04
Browser Chrome 94

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@fullstackninja864 fullstackninja864 marked this pull request as ready for review October 22, 2021 06:27
@thedoublejay thedoublejay marked this pull request as draft October 22, 2021 08:26
@fuxingloh
Copy link
Contributor

fuxingloh commented Oct 25, 2021

Following the idea of https://github.com/DeFiCh/wallet/blob/main/CONTRIBUTING.md#translation-guides to make translation more discoverable and easy to maintain contextually.

A while back I was trying to create a <Translate> component to make all "Translate-able" components a breeze to write and contextually relevant. I created this but didn't commit it.

import React, { createContext, PropsWithChildren, useContext } from 'react'
import { TranslateOptions } from 'i18n-js'
import { translate } from './index'

interface TranslateProps {
  text: string
  scope?: string
  options?: TranslateOptions
}

const TranslateContext = createContext<string>(undefined as any)

export function Translate (props: TranslateProps): JSX.Element {
  const scope = useContext(TranslateContext)
  return (
    // TODO: add TestId
    <>
      {translate(props.scope ?? scope, props.text, props.options)}
    </>
  )
}

Translate.Context = function (props: PropsWithChildren<{ scope: string }>): JSX.Element {
  return (
    <TranslateContext.Provider value={props.scope}>
      {props.children}
    </TranslateContext.Provider>
  )
}

export function useTranslate (text: string, options?: TranslateOptions): string {
  const scope = useContext(TranslateContext)
  return translate(scope, text, options)
}

This design creates automatically scoped "Translate Context" (aka your screens/context of where it will appear) and a more natural React-based <Translate text='' /> component where explicitly consistent with your node hierarchy.

export function MainView (): JSX.Element {
  function Alert (text: string): void {
    // Do something with text
  }

  return (
    <ThemedView>
      <Translate.Context scope='screens/MainView'>
        <Translate text='Title' />
        <Translate text='Body' />

        <TouchableOpacity onPress={() => {
          Alert(useTranslate('Where I must use `string` text'))
        }}>
          <Translate text='Some Text' scope='screens/AlternativeScope' />
        </TouchableOpacity>
      </Translate.Context>
    </ThemedView>
  )
}

Translation work is then contextually driven:

  1. you look at the context you are translating
  2. you translate the word within the context
  3. contexts are naturally hierarchical
  4. they are searchable with the English representation always being the key

Side note: How can we automatically generate the translation mapping? I don't have an answer for that yet.
Mabe running the app in debug mode will automatically index all the translation matrix into JSON file automatically?

@thedoublejay
Copy link
Contributor

Closing this for now, let's re-open another one once we're working on it again

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.

e2e - validate translated words
4 participants