insertHTMLFragments.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. This script will aid the process of inserting HTML fragments into all the
  3. locales.
  4. We are migrating from
  5. locale: 'PRE __key1__ POST'
  6. pug: translate(localeKey, { key1: '<b>VALUE</b>' })
  7. to
  8. locale: 'PRE <0>__key1__</0> POST'
  9. pug: translate(localeKey, { key1: 'VALUE' }, ['b'])
  10. MAPPING entries:
  11. localeKey: ['key1', 'key2']
  12. click_here_to_view_sl_in_lng: ['lngName']
  13. */
  14. const MAPPING = {
  15. support_lots_of_features: ['help_guides_link'],
  16. nothing_to_install_ready_to_go: ['start_now'],
  17. all_packages_and_templates: ['templatesLink'],
  18. github_merge_failed: ['sharelatex_branch', 'master_branch'],
  19. kb_suggestions_enquiry: ['kbLink'],
  20. sure_you_want_to_restore_before: ['filename'],
  21. you_have_added_x_of_group_size_y: ['addedUsersSize', 'groupSize'],
  22. x_price_per_month: ['price'],
  23. x_price_per_year: ['price'],
  24. x_price_for_first_month: ['price'],
  25. x_price_for_first_year: ['price'],
  26. sure_you_want_to_change_plan: ['planName'],
  27. subscription_canceled_and_terminate_on_x: ['terminateDate'],
  28. next_payment_of_x_collectected_on_y: ['paymentAmmount', 'collectionDate'],
  29. currently_subscribed_to_plan: ['planName'],
  30. recurly_email_update_needed: ['recurlyEmail', 'userEmail'],
  31. change_to_annual_billing_and_save: ['percentage', 'yearlySaving'],
  32. project_ownership_transfer_confirmation_1: ['user', 'project'],
  33. you_introed_high_number: ['numberOfPeople'],
  34. you_introed_small_number: ['numberOfPeople'],
  35. click_here_to_view_sl_in_lng: ['lngName'],
  36. }
  37. const { transformLocales } = require('./transformLocales')
  38. function transformLocale(locale, components) {
  39. components.forEach((key, idx) => {
  40. const i18nKey = `__${key}__`
  41. const replacement = `<${idx}>${i18nKey}</${idx}>`
  42. if (!locale.includes(replacement)) {
  43. locale = locale.replace(new RegExp(i18nKey, 'g'), replacement)
  44. }
  45. })
  46. return locale
  47. }
  48. function main() {
  49. transformLocales(MAPPING, transformLocale)
  50. }
  51. if (require.main === module) {
  52. main()
  53. }