How can bucket-sort handle integer keys in a range $[a, b]$, or string keys from a fixed set such as the names of the 50 US states?
Turn each key into an index first. For $[a, b]$, shift: entry $(k, o)$ goes into bucket $B[k - a]$, using $b - a + 1$ buckets. For strings from a fixed set $D$, sort $D$ once and use each string's rank $r(k)$, its position in the sorted $D$, as the bucket index $B[r(k)]$.
Shifting works because subtracting $a$ maps $a, a+1, \ldots, b$ onto $0, 1, \ldots, b - a$ without changing their order. Swiss postal codes, for example, run from 1000 to 9999: without the shift the first 1 000 buckets, a tenth of the array, would never be used, and with $B[k - 1000]$ the sort needs 9 000 buckets instead of 10 000. Negative keys need the shift anyway: temperatures from $-20$ to $40$ degrees go into $B[k + 20]$, 61 buckets.
For strings the trick is that the set of possible keys is fixed and small. Sorting the 50 state names once (Alabama is 0, Alaska 1, …, Wyoming 49) costs a constant amount of work, however many entries there are to sort. After that each entry only needs its key's rank, for example looked up in a hash map built from the sorted list, and the rest is an ordinary bucket-sort with 50 buckets: no two strings are compared during the sort itself.
In Java an enum provides such ranks for free. Declare the constants in sorted order, say the Swiss cantons as enum Canton { AG, AI, AR, BE, … }, and Canton.AR.ordinal() returns 2, its position counted from 0. That only works because the declaration order is the sort order.
Both are cases of one rule: bucket-sort works for any key type that can be mapped onto $0, \ldots, N-1$ in a way that keeps the order.