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

Remove unused locale messages #7190

Merged
merged 3 commits into from Sep 18, 2019
Merged

Remove unused locale messages #7190

merged 3 commits into from Sep 18, 2019

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 18, 2019

A number of unused locale messages have been removed - probably leftover from old UI elements that have since been removed.

The verify_locale_strings script has been augmented to search the UI for string literals, and match those against the locale message keys in the en locale. Any messages without a corresponding string literal are assumed to be unused.

The script has also been updated with an optional --fix parameter, which will automatically delete any unused messages from locales.

160 unused messages were found in this case, out of a total of about 650 messages. Another 70 messages are potentially unused and require further investigation, but weren't as easy to rule out because they were found in string literals.

@Gudahtt Gudahtt force-pushed the cleanup-locales branch 2 times, most recently from 5b3492b to 05f56e0 Compare September 18, 2019 18:29
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 18, 2019

Here's the list of removed messages:

  • exposeAccounts
  • exposeDescription
  • confirmExpose
  • clearApprovalDataSuccess
  • aboutUs
  • accept
  • addCustomToken
  • addEthAddress
  • agreeTermsOfService
  • allDone
  • alreadyHaveSeedPhrase
  • amountPlusGas
  • amountPlusTxFee
  • available
  • balances
  • beta
  • borrowDharma
  • buy
  • buyCoinbase
  • buyCoinbaseExplainer
  • cancelN
  • classicInterface
  • clickCopy
  • company
  • confirmationTime
  • confirmContract
  • confirmTransaction
  • connecting
  • connectingToUnknown
  • connectToLedger
  • connectToTrezor
  • continue
  • continueToCoinbase
  • copiedClipboard
  • copiedSafe
  • createDen
  • crypto
  • currentNetwork
  • currentRpc
  • customize
  • denExplainer
  • depositBTC
  • depositEth
  • depositFiat
  • depositFromAccount
  • depositShapeShift
  • depositShapeShiftExplainer
  • directDeposit
  • editNetwork
  • editAccountName
  • encryptNewDen
  • ensNameNotFound
  • enterPasswordConfirm
  • eth
  • exchangeRate
  • exportPrivateKeyWarning
  • fastest
  • feeChartTitle
  • followTwitter
  • fromToSame
  • gasLimitRequired
  • generatingSeed
  • gasPriceRequired
  • generatingTransaction
  • hereList
  • howToDeposit
  • holdEther
  • importAnAccount
  • importDen
  • importWithSeedPhrase
  • invalidGasParams
  • invalidRequest
  • jsonFail
  • keepTrackTokens
  • knowledgeDataBase
  • legal
  • limit
  • loose
  • loweCaseWords
  • min
  • minutesShorthand
  • mobileSyncTitle
  • needImportPassword
  • newPassword8Chars
  • newRecipient
  • showAdvancedOptions
  • hideAdvancedOptions
  • optionalNickname
  • noTransactionHistory
  • notFound
  • notStarted
  • oldUI
  • oldUIMessage
  • openInTab
  • or
  • outgoing
  • originalTotal
  • passwordCorrect
  • passwordMismatch
  • passwordShort
  • pleaseReviewTransaction
  • popularTokens
  • readMore
  • readMore2
  • receive
  • refundAddress
  • retryWithMoreGas
  • sampleAccountName
  • saveAsFile
  • saveSeedAsFile
  • secondsShorthand
  • select
  • selectService
  • selectAnAddress
  • selectAnAsset
  • sendTokensAnywhere
  • shapeshiftBuy
  • showQRCode
  • signMessage
  • sigRequested
  • spaceBetween
  • speedUpTitle
  • speedUpSubtitle
  • takesTooLong
  • tokenAddress
  • tokenSelection
  • tokenWarning1
  • transactionWithNonce
  • transactionUpdatedGas
  • transactionMemo
  • transactionNumber
  • transfers
  • trezorHardwareWallet
  • twelveWords
  • uiMigrationAnnouncement
  • uiWelcome
  • uiWelcomeMessage
  • unavailable
  • unknownNetworkId
  • usaOnly
  • useOldUI
  • vaultCreated
  • viewNetworkInfo
  • whatsThis
  • yourUniqueAccountImage
  • yourUniqueAccountImageDescription1
  • yourUniqueAccountImageDescription2
  • yourUniqueAccountImageDescription3

Edit: this as been updated to remove messages that were missed because they used a string template, explained here.

Edit: appDescription was also just removed - that is used in the manifest.

@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 18, 2019

I've found these additional messages that have corresponding string literals, but seem to be unused:
Messages not present in UI:

  • add
  • address
  • addressBook
  • editingTransaction
  • gas
  • gasFee
  • info
  • onlySendToEtherAddress
  • onlySendTokensToAccountAddress
  • restoreVault
  • rpc
  • status
  • tokenBalance
  • transactions
  • warning

development/verify-locale-strings.js Outdated Show resolved Hide resolved
development/verify-locale-strings.js Outdated Show resolved Hide resolved
Various message keys were being specified with a string template
instead of a string literal. They have been switched to use string
literals so that the script for detecting unused messages can find
them.
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 18, 2019

I've just updated this to restore a few messages on the connect-hardware screen that were using string templates for the message key. They've been updated here to no longer use string templates. These are the restored messages:

  • dontHaveAHardwareWallet
  • hardwareWallets
  • hardwareWalletsMsg
  • havingTroubleConnecting
  • readyToConnect
  • step1HardwareWallet
  • step1HardwareWalletMsg
  • step2HardwareWallet
  • step2HardwareWalletMsg
  • step3HardwareWallet
  • step3HardwareWalletMsg

A number of unused locale messages have been removed - probably
leftover from old UI elements that have since been removed.

The `verify_locale_strings` script has been augmented to search the UI
for string literals, and match those against the locale message keys in
the `en` locale. Any messages without a corresponding string literal
are assumed to be unused.

The script has also been updated with an optional `--fix` parameter,
which will automatically delete any unused messages from locales.

148 unused messages were found in this case, out of a total of about
650 messages. Another 70 messages are _potentially_ unused and require
further investigation, but weren't as easy to rule out because they
were found in string literals.
The following messages were more difficult to rule out because they
were present as string literals in the UI. They do appear to be
unused as locale keys though.

Here are the removed messages:
  - [ ] add
  - [ ] address
  - [ ] addressBook
  - [ ] editingTransaction
  - [ ] gas
  - [ ] gasFee
  - [ ] info
  - [ ] onlySendToEtherAddress
  - [ ] onlySendTokensToAccountAddress
  - [ ] restoreVault
  - [ ] rpc
  - [ ] status
  - [ ] tokenBalance
  - [ ] transactions
  - [ ] warning
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 18, 2019

This should be in a decent state to review now. I'm reasonably confident that everything in the first batch of messages I removed is truly unused. The second batch I'm less certain about - I certainly can't find them used anywhere, and I haven't noticed any console warnings about them being missing when using the app, but they might be worth some additional scrutiny.

They're listed here: #7190 (comment)

@metamaskbot
Copy link
Collaborator

Builds ready [2102594]

Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

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

Seems legit

//
// will check the given locale against the strings in english
// This script will validate that locales have no unused messages. It will check
Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like we might want the inverse also, based on the concerns you've raised: Validate that no UI template call uses a non-existent message. Not sure how efficiently this can be done, but if we assume the template string is always in a t() call, it might be efficient enough to regex.

Just nervous about removing used messages, like you suggested might be the case!

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this already but too many cases use variables instead of string literals.

Many of those cases could be eliminated pretty easy, but there are a few that are very dynamic that would be challenging to refactor.

A better way to catch these cases might be to send an error to Sentry when we detect a missing key from the en locale, rather than just print a console warning like we do now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that'd be a good use of sentry.

Copy link
Contributor

@danfinlay danfinlay left a comment

Choose a reason for hiding this comment

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

Coupled with some sentry reporting in the case of a missing string, this should be fine. That's a lot of removed dead lines!

@Gudahtt Gudahtt merged commit 48bf2f8 into develop Sep 18, 2019
@whymarrh whymarrh deleted the cleanup-locales branch September 18, 2019 23:36
Gudahtt added a commit to Gudahtt/metamask-extension that referenced this pull request Sep 27, 2019
* origin/develop: (56 commits)
  Add advanced setting to enable editing nonce on confirmation screens (MetaMask#7089)
  Add migration on 3box imports and remove feature flag (MetaMask#7209)
  ci - install deps - limit install scripts to whitelist (MetaMask#7208)
  Add a/b test for full screen transaction confirmations (MetaMask#7162)
  Update minimum Firefox verison to 56.0 (MetaMask#7213)
  mesh-testing - submit infura rpc requests to mesh-testing container (MetaMask#7031)
  obs-store/local-store should upgrade webextension error to real error (MetaMask#7207)
  sesify-viz - bump dep for visualization enhancement (MetaMask#7175)
  address book entries by chainId (MetaMask#7205)
  Optimize images only during production build (MetaMask#7194)
  Use common test build during CI (MetaMask#7196)
  Report missing `en` locale messages to Sentry (MetaMask#7197)
  Verify locales on CI (MetaMask#7199)
  updated ganache and addons-linter (MetaMask#7204)
  fixup! add user rejected errors
  add user rejected errors
  update json-rpc-engine
  use eth-json-rpc-errors
  Remove unused locale messages (MetaMask#7190)
  Remove unused components (MetaMask#7191)
  ...
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.

None yet

4 participants