WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.35k stars 970 forks source link

Config for web monetization #7529

Closed SethFalco closed 2 years ago

SethFalco commented 2 years ago

Describe the problem

I think it'd be great if Web Monetization was more established, and if hosts of Weblate servers could receive additional support from users.

Web Monetization is a proposed W3C standard for monetization on the internet.

TL;DR: Creators and websites who choose to create an Interledger Payment Pointer can embed it in the <head> element of a webpage, and users who opt-in to support such websites can stream micropayments to financially support it.

It's like Brave Rewards (for creators) except Web Monetization is a proposed W3 standard, so it's not bound to a particular browser or account.

Describe the solution you'd like

There should be a new setting where users can configure a list of payment pointers. If specified, Weblate will add this list in the <head> of the document.

When there is only one payment pointer, it's as simple as adding:

<meta name="monetization" content="$alice.example">

If the config supports multiple payment points, which is a use-case that's officially documented on the Web Monetization site, it requires some extra JavaScript/PHP. Something to the effect of:

<head>
  <script>
    // Interledger Payment Pointer mapped to weight
    const pointers = {
      '$alice.example': 50,
      '$bob.example': 40,
      '$connie.example': 9.5,
      '$dave.example': 0.5
    }

    function pickPointer () {
      const sum = Object.values(pointers).reduce((sum, weight) => sum + weight, 0);
      let choice = Math.random() * sum;

      for (const pointer in pointers) {
        const weight = pointers[pointer]
        if ((choice -= weight) <= 0) {
          return pointer
        }
      }
    }

    window.addEventListener('load', () => {
      const monetizationTag = document.createElement('meta')
      monetizationTag.name = 'monetization'
      monetizationTag.content = pickPointer()

      document.head.appendChild(monetizationTag)
    })
  </script>
</head>

https://webmonetization.org/docs/probabilistic-rev-sharing#code

Describe alternatives you've considered

Instead of calculating the probabilistic revenue sharing yourself, it could be easier to use the API Web Monetization provide for it.

Suppose a config like, where the values are the Interledger Payment Pointer, weight, and a name:

[
  [
    "$alice.example",
    1,
    "Alice"
  ],
  [
    "$bob.example",
    1,
    "Bob"
  ]
]

Just minify, stringify, and base64 encode (padding can be removed) it. W1siJGFsaWNlLmV4YW1wbGUiLDEsIkFsaWNlIl0sWyIkYm9iLmV4YW1wbGUiLDEsIkJvYiJdXQ

With this, you can create a valid payment pointer where webmonetization.org handles the revenue sharing for you.

<meta name="monetization" content="$webmonetization.org/api/revshare/pay/W1siJGFsaWNlLmV4YW1wbGUiLDEsIkFsaWNlIl0sWyIkYm9iLmV4YW1wbGUiLDEsIkJvYiJdXQ">

More info: https://webmonetization.org/prob-revshare

I wouldn't recommend this though, it'd be an unnecessary dependency on another service.

Screenshots

No response

Additional context

I'd be happy to work on this, just wanted to note it here already in case the idea isn't favorable.

github-actions[bot] commented 2 years ago

The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.