Giter Site home page Giter Site logo

Feature: uui-time-ago about umbraco.ui HOT 12 OPEN

umbraco avatar umbraco commented on August 16, 2024
Feature: uui-time-ago

from umbraco.ui.

Comments (12)

bjarnef avatar bjarnef commented on August 16, 2024 1

@nielslyngsoe you may also want to look at this example to render relative time, which also use Intl.RelativeTimeFormat API: https://shoelace.style/components/relative-time

from umbraco.ui.

leekelleher avatar leekelleher commented on August 16, 2024 1

FYI, GitHub (the org) has a bundle of elements that extend the native <time> element:
<local-time>, <relative-time> and <time-ago>
https://github.com/github/time-elements

I found these on the Awesome Standalones repo, (for framework-agnostic standalone web components).

from umbraco.ui.

bjarnef avatar bjarnef commented on August 16, 2024 1

@warrenbuckley not yet, so feel free start working on this :)

from umbraco.ui.

bjarnef avatar bjarnef commented on August 16, 2024

@nielslyngsoe I just saw this on Twitter: https://twitter.com/Steve8708/status/1504131981444980739

Maybe a similar utility function?
Not sure what it return right after midnight though.

from umbraco.ui.

bjarnef avatar bjarnef commented on August 16, 2024

@leekelleher that's probably a good idea to extend the native <time> element.

It also use Intl.RelativeTimeFormat API as well via some utility methods:
https://github.com/github/time-elements/blob/main/src/utils.ts#L166-L179

Update: I think these functions were moved to here: https://github.com/github/relative-time-element/blob/main/src/relative-time-element.ts#L116-L200

from umbraco.ui.

warrenbuckley avatar warrenbuckley commented on August 16, 2024

@bjarnef you planning on working this, if not I may try and give this a go :)

from umbraco.ui.

iOvergaard avatar iOvergaard commented on August 16, 2024

@warrenbuckley great that you'd like to take a stab at it! FYI, the component should handle the lang attribute directly as well as observe the lang attribute set on the browser element through the global variable known as document.documentElement.lang. I'm not sure if the Intl API picks up on this automatically. In the backoffice at least, we have to listen for changes to that attribute.

from umbraco.ui.

bjarnef avatar bjarnef commented on August 16, 2024

@iOvergaard the component could probably observe document lang attribute, but not sure if there's a need to specify a different language than backoffice language (or if used in other contexts). I this this Shoelace component may use default language in
https://shoelace.style/components/relative-time#localization

I think they handled English as the default/fallback language as part of the localization utility.
https://github.com/shoelace-style/shoelace/blob/7500cabc587abead71f2440ad8f87aa4c1f468f9/src/utilities/localize.ts#L2

Not sure if the localization in UI library or backoffice is aware of the locale/culture, but also other stuff like direction (LTR / RTL).
https://www.w3.org/International/questions/qa-html-dir

It seems the direction in that library was defined in each language:
https://github.com/shoelace-style/shoelace/blob/7500cabc587abead71f2440ad8f87aa4c1f468f9/src/utilities/localize.ts#L14

from umbraco.ui.

iOvergaard avatar iOvergaard commented on August 16, 2024

@bjarnef

not sure if there's a need to specify a different language than backoffice language

No, probably not, but how does it get the backoffice language. Does the Intl Api get it from the lang attribute automatically?

from umbraco.ui.

bjarnef avatar bjarnef commented on August 16, 2024

@iOvergaard this project https://github.com/github/relative-time-element seems to get language from closest lang attribute: https://github.com/github/relative-time-element/blob/main/src/relative-time-element.ts#L84-L90

Regarding Intl.RelativeTimeFormat() I think it use en if locale is not provided.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat

image

from umbraco.ui.

bjarnef avatar bjarnef commented on August 16, 2024

Lang is a built-in global attribute. Relative Time will use this to provide an applicable language to the Intl APIs. If the individual element does not have a lang attribute then it will traverse upwards in the tree to find the closest element that does, or default the lang to en.

https://github.com/github/relative-time-element#lang

from umbraco.ui.

warrenbuckley avatar warrenbuckley commented on August 16, 2024

@bjarnef you seem to be more active on this and realistically with my workload and little free time I doubt I will get to this, so if you have been working on this please feel free to as I won't be right now.

from umbraco.ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.